コード例 #1
0
ファイル: classMedia.php プロジェクト: NewRoute/glfusion
 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;
 }
コード例 #2
0
ファイル: video.php プロジェクト: NewRoute/glfusion
if ($nRows > 0) {
    $row = DB_fetchArray($result);
    $aid = $row['album_id'];
    if ($MG_albums[$aid]->access == 0) {
        $display = MG_siteHeader();
        $display .= COM_showMessageText($LANG_MG00['access_denied_msg'], $LANG_ACCESS['accessdenied'], true);
        $display .= MG_siteFooter();
        echo $display;
        exit;
    }
    $T = new Template(MG_getTemplatePath($aid));
    $T->set_var('site_url', $_CONF['site_url']);
    $T->set_var('themeCSS', MG_getThemeCSS($aid));
    $T->set_var('charset', $charset);
    $meta_file_name = $_MG_CONF['path_mediaobjects'] . 'orig/' . $row['media_filename'][0] . '/' . $row['media_filename'] . '.' . $row['media_mime_ext'];
    $meta = IMG_getMediaMetaData($meta_file_name);
    if ($meta['mime_type'] == 'video/quicktime') {
        if ($meta['fileformat'] == 'mp4') {
            $row['mime_type'] = 'video/mp4';
        }
    }
    switch ($row['mime_type']) {
        case 'embed':
            $T->set_file('video', 'embed.thtml');
            $T->set_var(array('video' => 'embed.thtml', 'embed_string' => $row['remote_url'], 'media_title' => PLG_replaceTags($row['media_title'], 'mediagallery', 'media_title'), 'media_tag' => strip_tags($row['media_title'])));
            break;
        case 'application/x-shockwave-flash':
            $T->set_file('video', 'swf.thtml');
            $T->set_var('movie', $_MG_CONF['mediaobjects_url'] . '/orig/' . $row['media_filename'][0] . '/' . $row['media_filename'] . '.' . $row['media_mime_ext']);
            $T->set_var('title', $row['media_title']);
            $playback_options['play'] = $_MG_CONF['swf_play'];
コード例 #3
0
ファイル: lib-image.php プロジェクト: NewRoute/glfusion
function IMG_squareThumbnail($srcImage, $destImage, $dSize, $mimeType = '', $deleteSrc = 0)
{
    $imgsize = @getimagesize("{$srcImage}");
    $original_width = $imgsize[0];
    $original_height = $imgsize[1];
    if ($mimeType == '') {
        $metaData = IMG_getMediaMetaData($srcImage);
        $mimeType = $metaData['mime_type'];
    }
    list($rc, $msg) = _img_squareThumbnail($srcImage, $destImage, $original_height, $original_width, $dSize, $mimeType);
    if ($rc == false) {
        return array($rc, $msg);
    }
    return array(true, 'Image successfully resized');
}
コード例 #4
0
ファイル: autotag.inc.php プロジェクト: spacequad/glfusion
function _mg_autotags($op, $content = '', $autotag = '')
{
    global $MG_albums, $_MG_CONF, $_CONF, $_MG_USERPREFS, $_TABLES, $LANG_MG00, $LANG_MG03, $side_count, $swfjsinclude;
    global $mgAutoTagArray, $mg_installed_version;
    static $ss_count = 0;
    if ($mg_installed_version != $_MG_CONF['pi_version']) {
        return $content;
    }
    $default_thumbnail = 'placeholder.svg';
    if ($op == 'parse') {
        if (!isset($mgAutoTagArray['count']) || empty($mgAutoTagArray['count'])) {
            $mgAutoTagArray['count'] = 0;
        }
        /*
         * Process the auto tag to remove any embedded &nbsp;
         */
        $tag = str_replace('&nbsp;', ' ', $autotag['tagstr']);
        $parms = explode(' ', $tag);
        // Extra test to see if autotag was entered with a space
        // after the module name
        if (substr($parms[0], -1) == ':') {
            $startpos = strlen($parms[0]) + strlen($parms[1]) + 2;
            $label = str_replace(']', '', substr($tag, $startpos));
            $tagid = $parms[1];
        } else {
            $label = str_replace(']', '', substr($tag, strlen($parms[0]) + 1));
            $parms = explode(':', $parms[0]);
            if (count($parms) > 2) {
                // whoops, there was a ':' in the tag id ...
                array_shift($parms);
                $tagid = implode(':', $parms);
            } else {
                $tagid = $parms[1];
            }
        }
        $autotag['parm1'] = str_replace(']', '', $tagid);
        $autotag['parm2'] = $label;
        /*
         * end of tag replacement
         */
        $T = new Template($_MG_CONF['template_path']);
        // see if we have an alignment option included
        $caption = $autotag['parm2'];
        $aSet = 0;
        $skip = 0;
        // default values for parameters
        $border = $_MG_CONF['at_border'];
        $align = $_MG_CONF['at_align'];
        $width = $_MG_CONF['at_width'];
        $height = $_MG_CONF['at_height'];
        $src = $_MG_CONF['at_src'];
        $autoplay = $_MG_CONF['at_autoplay'];
        $enable_link = $_MG_CONF['at_enable_link'];
        $delay = $_MG_CONF['at_delay'];
        $transition = 'Fade';
        $showtitle = $_MG_CONF['at_showtitle'];
        $destination = 'content';
        $target = '';
        $linkID = 0;
        $alt = 0;
        $link_src = 'disp';
        $classes = '';
        $nosize = 0;
        $tag = '';
        if ($align != '') {
            $aSet = 1;
        }
        // parameter processing - logic borrowed from
        // Dirk Haun's Flickr plugin
        $px = explode(' ', trim($autotag['parm2']));
        if (is_array($px)) {
            foreach ($px as $part) {
                if (substr($part, 0, 6) == 'width:') {
                    $a = explode(':', $part);
                    $width = $a[1];
                    $skip++;
                } elseif (substr($part, 0, 7) == 'height:') {
                    $a = explode(':', $part);
                    $height = $a[1];
                    $skip++;
                } elseif (substr($part, 0, 7) == 'border:') {
                    $a = explode(':', $part);
                    $border = $a[1];
                    $skip++;
                } elseif (substr($part, 0, 6) == 'align:') {
                    $a = explode(':', $part);
                    $align = $a[1];
                    $skip++;
                    $aSet = 1;
                } elseif (substr($part, 0, 4) == 'src:') {
                    $a = explode(':', $part);
                    $src = $a[1];
                    $skip++;
                } elseif (substr($part, 0, 9) == 'autoplay:') {
                    $a = explode(':', $part);
                    $autoplay = $a[1];
                    $skip++;
                } elseif (substr($part, 0, 5) == 'link:') {
                    $a = explode(':', $part);
                    $enable_link = $a[1];
                    $skip++;
                } elseif (substr($part, 0, 6) == 'delay:') {
                    $a = explode(':', $part);
                    $delay = $a[1];
                    $skip++;
                } elseif (substr($part, 0, 11) == 'transition:') {
                    $a = explode(':', $part);
                    $transition = $a[1];
                    $skip++;
                } elseif (substr($part, 0, 6) == 'title:') {
                    $a = explode(':', $part);
                    $showtitle = $a[1];
                    $skip++;
                } elseif (substr($part, 0, 5) == 'dest:') {
                    $a = explode(':', $part);
                    $destination = $a[1];
                    $skip++;
                    if ($destination != 'content' && $destination != 'block') {
                        $destination = 'content';
                    }
                } elseif (substr($part, 0, 7) == 'linkid:') {
                    $a = explode(':', $part);
                    $linkID = $a[1];
                    $skip++;
                } elseif (substr($part, 0, 4) == 'alt:') {
                    $a = explode(':', $part);
                    $alt = $a[1];
                    $skip++;
                } elseif (substr($part, 0, 7) == 'target:') {
                    $a = explode(':', $part);
                    $target = $a[1];
                    $skip++;
                } elseif (substr($part, 0, 5) == 'type:') {
                    $a = explode(':', $part);
                    $mp3_type = $a[1];
                    $skip++;
                } elseif (substr($part, 0, 6) == 'class:') {
                    $a = explode(':', $part);
                    $c = explode(',', $a[1]);
                    foreach ($c as $class) {
                        $classes .= ' ' . $class;
                    }
                    $skip++;
                } elseif (substr($part, 0, 7) == 'nosize:') {
                    $a = explode(':', $part);
                    $nosize = $a[1];
                    $skip++;
                } elseif (substr($part, 0, 4) == 'tag:') {
                    $a = explode(':', $part);
                    $tag = str_replace('_', ' ', $a[1]);
                    $skip++;
                } elseif (substr($part, 0, 8) == 'linksrc:') {
                    $a = explode(':', $part);
                    $link_src = $a[1];
                    if (!in_array($link_src, array('tn', 'disp', 'orig'))) {
                        $link_src = 'disp';
                    }
                    $skip++;
                } else {
                    break;
                }
            }
            if ($skip != 0) {
                if (count($px) > $skip) {
                    for ($i = 0; $i < $skip; $i++) {
                        array_shift($px);
                    }
                    $caption = trim(implode(' ', $px));
                } else {
                    $caption = '';
                }
            }
        } else {
            $caption = trim($autotag['parm2']);
        }
        if ($tag == '') {
            $tag = $caption;
        }
        if (!is_numeric($autotag['parm1'][0])) {
            switch ($autotag['parm1'][0]) {
                case 'n':
                    $align = '';
                    $aSet = 1;
                    break;
                case 'c':
                    $align = "center";
                    $aSet = 1;
                    break;
                case 'l':
                    $align = "left";
                    $aSet = 1;
                    break;
                case 'r':
                    $align = "right";
                    $aSet = 1;
                    break;
                case 'a':
                    $align = !($side_count % 2) ? "left" : "right";
                    $side_count++;
                    $aSet = 1;
                    break;
                default:
                    $align = !($side_count % 2) ? "left" : "right";
                    $side_count++;
                    break;
            }
            $parm1 = COM_applyFilter(substr($autotag['parm1'], 1, strlen($autotag['parm1']) - 1));
        } else {
            $parm1 = COM_applyFilter($autotag['parm1']);
            if ($aSet == 0 || $align == 'auto') {
                $align = !($side_count % 2) ? "left" : "right";
                $side_count++;
            }
        }
        if ($align == 'none') {
            $align = '';
        }
        if (!in_array($autotag['tag'], array('album', 'media', 'img', 'slideshow', 'fslideshow', 'video', 'audio', 'download', 'image', 'oimage', 'mlink', 'alink', 'playall'))) {
            return $content;
        }
        MG_initAlbums();
        // sanity check incase the album has been deleted or something...
        if ($autotag['tag'] != 'media' && $autotag['tag'] != 'image' && $autotag['tag'] != 'video' && $autotag['tag'] != 'audio' && $autotag['tag'] != 'download' && $autotag['tag'] != 'oimage' && $autotag['tag'] != 'img' && $autotag['tag'] != 'mlink' && $autotag['tag'] != 'alink' && $autotag['tag'] != 'playall') {
            if (!isset($MG_albums[$parm1]->id)) {
                $link = '';
                $content = str_replace($autotag['tagstr'], $link, $content);
                return $content;
            }
        }
        $ss_count = mt_rand(0, 32768);
        switch ($autotag['tag']) {
            case 'download':
                $side_count--;
                $sql = "SELECT ma.album_id FROM {$_TABLES['mg_media']} AS m LEFT JOIN {$_TABLES['mg_media_albums']} AS ma ON m.media_id=ma.media_id WHERE m.media_id='" . DB_escapeString($parm1) . "'";
                $result = DB_query($sql);
                if (DB_numRows($result) > 0) {
                    $row = DB_fetchArray($result);
                    $aid = $row['album_id'];
                    if (!isset($MG_albums[$aid]->id) || $MG_albums[$aid]->access == 0) {
                        $link = '';
                        $content = str_replace($autotag['tagstr'], $link, $content);
                        return $content;
                    }
                    $link = '<a href="' . $_MG_CONF['site_url'] . '/download.php?mid=' . $parm1 . '">';
                    if ($caption != "") {
                        $link .= $caption;
                    } else {
                        $link .= 'download';
                    }
                    $link .= '</a>';
                    if ($destination != 'block') {
                        $content = str_replace($autotag['tagstr'], $link, $content);
                    } else {
                        $autoTagCount = $mgAutoTagArray['count'];
                        $mgAutoTagArray['tags'][$autoTagCount] = $link;
                        $mgAutoTagArray['count']++;
                        $link = '';
                        $content = str_replace($autotag['tagstr'], $link, $content);
                    }
                    return $content;
                } else {
                    $link = '';
                    $content = str_replace($autotag['tagstr'], $link, $content);
                    return $content;
                }
                break;
            case 'mlink':
                $side_count--;
                $sql = "SELECT m.remote_url,ma.album_id FROM {$_TABLES['mg_media']} AS m LEFT JOIN {$_TABLES['mg_media_albums']} AS ma ON m.media_id=ma.media_id WHERE m.media_id='" . DB_escapeString($parm1) . "'";
                $result = DB_query($sql);
                if (DB_numRows($result) > 0) {
                    $row = DB_fetchArray($result);
                    $aid = $row['album_id'];
                    if (!isset($MG_albums[$aid]->id) || $MG_albums[$aid]->access == 0) {
                        $link = '';
                        $content = str_replace($autotag['tagstr'], $link, $content);
                        return $content;
                    }
                    if ($alt == 1 && $row['remote_url'] != '') {
                        $link = '<a href="' . $row['remote_url'] . '"' . ($target == '' ? '' : ' target="' . $target . '"') . '>';
                    } else {
                        $link = '<a href="' . $_MG_CONF['site_url'] . '/media.php?f=0&amp;sort=0&amp;s=' . $parm1 . '"' . ($target == '' ? '' : ' target="' . $target . '"') . '>';
                    }
                    if ($caption != "") {
                        $link .= $caption;
                    } else {
                        $link .= $LANG_MG03['click_here'];
                    }
                    $link .= '</a>';
                    if ($destination != 'block') {
                        $content = str_replace($autotag['tagstr'], $link, $content);
                    } else {
                        $autoTagCount = $mgAutoTagArray['count'];
                        $mgAutoTagArray['tags'][$autoTagCount] = $link;
                        $mgAutoTagArray['count']++;
                        $link = '';
                        $content = str_replace($autotag['tagstr'], $link, $content);
                    }
                    $content = str_replace($autotag['tagstr'], $link, $content);
                    return $content;
                } else {
                    $link = '';
                    $content = str_replace($autotag['tagstr'], $link, $content);
                    return $content;
                }
                break;
            case 'playall':
                if (!isset($MG_albums[$parm1]->id) || $MG_albums[$parm1]->access == 0 || COM_isAnonUser() && $_MG_CONF['loginrequired'] == 1) {
                    $link = '';
                    $content = str_replace($autotag['tagstr'], $link, $content);
                    return $content;
                }
                $V = new Template(MG_getTemplatePath(0));
                $V->set_file(array('xspf' => 'xspf_radio.thtml'));
                $V->set_var(array('aid' => $parm1, 'site_url' => $_MG_CONF['site_url'], 'autoplay' => $autoplay ? 'play' : 'stop', 'id' => 'mp3radio' . rand(), 'id2' => 'mp3radio' . rand()));
                $V->parse('output', 'xspf');
                if ($align != '' && $align != "center") {
                    $link = '<span style="float:' . $align . ';padding:5px;">' . $V->finish($V->get_var('output')) . '</span>';
                } else {
                    if ($align == "center") {
                        $link = '<span style="text-align:center;padding:5px;">' . $V->finish($V->get_var('output')) . '</span>';
                    } else {
                        $link = '<span style="padding:5px;">' . $V->finish($V->get_var('output')) . '</span>';
                    }
                }
                if ($destination != 'block') {
                    $content = str_replace($autotag['tagstr'], $link, $content);
                } else {
                    $autoTagCount = $mgAutoTagArray['count'];
                    $mgAutoTagArray['tags'][$autoTagCount] = $link;
                    $mgAutoTagArray['count']++;
                    $link = '';
                    $content = str_replace($autotag['tagstr'], $link, $content);
                }
                $content = str_replace($autotag['tagstr'], $link, $content);
                return $content;
                break;
            case 'video':
                $sql = "SELECT ma.album_id,m.media_id,m.mime_type,m.remote_url,m.media_filename,m.media_mime_ext,m.media_original_filename,m.media_tn_attached,m.media_resolution_x,m.media_resolution_y,m.remote_media FROM {$_TABLES['mg_media']} AS m LEFT JOIN {$_TABLES['mg_media_albums']} AS ma ON m.media_id=ma.media_id WHERE m.media_id='" . DB_escapeString($parm1) . "'";
                $result = DB_query($sql);
                if (DB_numRows($result) > 0) {
                    $row = DB_fetchArray($result);
                    $aid = $row['album_id'];
                    if (!isset($MG_albums[$aid]->id) || $MG_albums[$aid]->access == 0) {
                        $link = '';
                        $content = str_replace($autotag['tagstr'], $link, $content);
                        return $content;
                    }
                    $meta_file_name = $_MG_CONF['path_mediaobjects'] . 'orig/' . $row['media_filename'][0] . '/' . $row['media_filename'] . '.' . $row['media_mime_ext'];
                    $meta = IMG_getMediaMetaData($meta_file_name);
                    if ($meta['mime_type'] == 'video/quicktime' || $meta['mime_type'] == 'video/mp4') {
                        if ($meta['fileformat'] == 'mp4') {
                            $row['mime_type'] = 'video/mp4';
                        }
                    }
                    // determine height / width and aspect
                    if (($width == 'auto' || $width == 0 || $width == -1 || $height == -1) && $row['media_resolution_x'] > 0 && $row['media_resolution_y'] > 0) {
                        $videoheight = $row['media_resolution_y'];
                        $videowidth = $row['media_resolution_x'];
                    } else {
                        if ($row['media_resolution_x'] > 0 && $row['media_resolution_y'] > 0) {
                            if ($row['media_resolution_x'] >= $row['media_resolution_y']) {
                                // landscape
                                $ratio = $row['media_resolution_y'] / $row['media_resolution_x'];
                                $orientation = 0;
                            } else {
                                // portrait
                                $ratio = $row['media_resolution_x'] / $row['media_resolution_y'];
                                $orientation = 1;
                            }
                        } else {
                            $ratio = 0.75;
                            $orientation = 0;
                        }
                        if ($orientation == 0) {
                            if ($width > 0 && $height == 0) {
                                $videoheight = round($width * $ratio);
                                $videowidth = $width;
                            } else {
                                if ($width == 0 && $height == 0) {
                                    $videoheight = 200 * $ratio;
                                    $videowidth = 200;
                                } else {
                                    if ($width == 0 && $height > 0) {
                                        $videowidth = round($height / $ratio);
                                        $videoheight = $height;
                                    } else {
                                        if ($width > 0 && $height > 0) {
                                            $videowidth = $width;
                                            $videoheight = $height;
                                        }
                                    }
                                }
                            }
                        } else {
                            if ($width > 0 && $height == 0) {
                                $videoheight = round($width / $ratio);
                                $videowidth = $width;
                            } else {
                                if ($width == 0 && $height == 0) {
                                    $videoheight = 200;
                                    $videowidth = round(200 / $ratio);
                                } else {
                                    if ($width == 0 && $height > 0) {
                                        $videowidth = round($height * $ratio);
                                        $videoheight = $height;
                                    } else {
                                        if ($width > 0 && $height > 0) {
                                            $videowidth = $width;
                                            $videoheight = $height;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    switch ($row['mime_type']) {
                        case 'embed':
                            if (preg_match("/vimeo/i", $row['remote_url'])) {
                                $vimeo = 'vimeo, ';
                            } else {
                                $vimeo = '';
                            }
                            if ($align != '' && $align != "center") {
                                $link = '<div class="js-video [' . $vimeo . 'widescreen] ' . $classes . '"><span style="float:' . $align . ';padding:5px;">' . $row['remote_url'] . '</span></div>';
                            } else {
                                if ($align == 'center') {
                                    $link = '<div class="js-video [' . $vimeo . 'widescreen] ' . $classes . '"><span style="text-align:center;padding:5px;">' . $row['remote_url'] . '</span></div>';
                                } else {
                                    $link = '<div class="js-video [' . $vimeo . 'widescreen] ' . $classes . '"><span style="padding:5px;">' . $row['remote_url'] . '</span></div>';
                                }
                            }
                            if ($destination != 'block') {
                                $content = str_replace($autotag['tagstr'], $link, $content);
                            } else {
                                $autoTagCount = $mgAutoTagArray['count'];
                                $mgAutoTagArray['tags'][$autoTagCount] = $link;
                                $mgAutoTagArray['count']++;
                                $link = '';
                                $content = str_replace($autotag['tagstr'], $link, $content);
                            }
                            return $content;
                            break;
                        case 'video/x-ms-asf':
                        case 'video/x-ms-asf-plugin':
                        case 'video/avi':
                        case 'video/msvideo':
                        case 'video/x-msvideo':
                        case 'video/avs-video':
                        case 'video/x-ms-wmv':
                        case 'video/x-ms-wvx':
                        case 'video/x-ms-wm':
                        case 'application/x-troff-msvideo':
                        case 'application/x-ms-wmz':
                        case 'application/x-ms-wmd':
                            $V = new Template(MG_getTemplatePath(0));
                            $V->set_file('video', 'view_asf.thtml');
                            $V->set_var(array('autostart' => $autoplay ? 'true' : 'false', 'enablecontextmenu' => 'true', 'stretchtofit' => 'false', 'showstatusbar' => 'false', 'showcontrols' => 'true', 'showdisplay' => 'false', 'height' => $videoheight, 'width' => $videowidth, 'bgcolor' => '#FFFFFF', 'playcount' => '9999', 'loop' => 'true', 'movie' => $_MG_CONF['mediaobjects_url'] . '/orig/' . $row['media_filename'][0] . '/' . $row['media_filename'] . '.' . $row['media_mime_ext'], 'autostart0' => $autoplay ? '1' : '0', 'enablecontextmenu0' => '1', 'stretchtofit0' => '0', 'showstatusbar0' => '0', 'uimode0' => 'none', 'showcontrols0' => '1', 'showdisplay0' => '0'));
                            $V->parse('output', 'video');
                            if ($align != '' && $align != "center") {
                                $u_image = '<span style="float:' . $align . ';padding:5px;">' . $V->finish($V->get_var('output')) . '</span>';
                            } else {
                                if ($align == 'center') {
                                    $u_image = '<span style="text-align:center;padding:5px;">' . $V->finish($V->get_var('output')) . '</span>';
                                } else {
                                    $u_image = '<span style="padding:5px;">' . $V->finish($V->get_var('output')) . '</span>';
                                }
                            }
                            break;
                        case 'video/mp4':
                            if ($row['media_tn_attached'] == 1) {
                                $foundTN = 0;
                                foreach ($_MG_CONF['validExtensions'] as $ext) {
                                    if (file_exists($_MG_CONF['path_mediaobjects'] . '/orig/' . $row['media_filename'][0] . '/tn_' . $row['media_filename'] . $ext)) {
                                        $thumb = $_MG_CONF['mediaobjects_url'] . '/orig/' . $row['media_filename'][0] . '/tn_' . $row['media_filename'] . $ext;
                                        $media_size_orig = $media_size_disp = @getimagesize($_MG_CONF['path_mediaobjects'] . '/orig/' . $row['media_filename'][0] . '/tn_' . $row['media_filename'] . $ext);
                                        $foundTN = 1;
                                        break;
                                    }
                                }
                                if ($foundTN == 0) {
                                    foreach ($_MG_CONF['validExtensions'] as $ext) {
                                        if (file_exists($_MG_CONF['path_mediaobjects'] . '/tn/' . $row['media_filename'][0] . '/tn_' . $row['media_filename'] . $ext)) {
                                            $thumb = $_MG_CONF['mediaobjects_url'] . '/tn/' . $row['media_filename'][0] . '/tn_' . $row['media_filename'] . $ext;
                                            $media_size_orig = $media_size_disp = @getimagesize($_MG_CONF['path_mediaobjects'] . '/tn/' . $row['media_filename'][0] . '/tn_' . $row['media_filename'] . $ext);
                                            break;
                                        }
                                    }
                                }
                            } else {
                                $thumb = '';
                                //$_MG_CONF['mediaobjects_url'] . '/video-placeholder.png';
                                //                                $thumb = $_MG_CONF['mediaobjects_url'].'/placeholder_video_w.svg';
                            }
                            $V = new Template(MG_getTemplatePath(0));
                            $V->set_file(array('video' => 'view_mp4.thtml'));
                            $V->set_var(array('mime_type' => 'video/mp4', 'autoref' => 'true', 'autoplay' => $autoplay ? 'true' : 'false', 'autoplay_text' => $autoplay ? ' autoplay ' : '', 'controller' => 'true', 'kioskmode' => 'true', 'scale' => 'aspect', 'height' => $videoheight, 'width' => $videowidth, 'bgcolor' => '#F0F0F0', 'loop' => 'true', 'movie' => $_MG_CONF['mediaobjects_url'] . '/orig/' . $row['media_filename'][0] . '/' . $row['media_filename'] . '.' . $row['media_mime_ext'], 'thumbnail' => $thumb, 'site_url' => $_MG_CONF['site_url'], 'player_url' => $_CONF['site_url'] . '/javascript/addons/mediaplayer/'));
                            if ($align != '' && $align != "center") {
                                $V->set_var('alignment', 'float:' . $align . ';');
                            } else {
                                if ($align == 'center') {
                                    $V->set_var('alignment', 'text-align:center;');
                                } else {
                                    $V->set_var('alignment', 'text-align:center;');
                                }
                            }
                            $V->parse('output', 'video');
                            $u_image = $V->finish($V->get_var('output'));
                            break;
                        case 'video/mpeg':
                        case 'video/x-motion-jpeg':
                        case 'video/quicktime':
                        case 'video/mpeg':
                        case 'video/x-mpeg':
                        case 'video/x-mpeq2a':
                        case 'video/x-qtc':
                        case 'video/x-m4v':
                            $V = new Template(MG_getTemplatePath(0));
                            $V->set_file(array('video' => 'view_quicktime.thtml'));
                            $V->set_var(array('autoref' => 'true', 'autoplay' => $autoplay ? 'true' : 'false', 'controller' => 'true', 'kioskmode' => 'true', 'scale' => 'aspect', 'height' => $videoheight, 'width' => $videowidth, 'bgcolor' => '#F0F0F0', 'loop' => 'true', 'movie' => $_MG_CONF['mediaobjects_url'] . '/orig/' . $row['media_filename'][0] . '/' . $row['media_filename'] . '.' . $row['media_mime_ext']));
                            $V->parse('output', 'video');
                            if ($align != '' && $align != "center") {
                                $u_image = '<div style="float:' . $align . ';padding:5px;">' . $V->finish($V->get_var('output')) . '</div>';
                            } else {
                                if ($align == 'center') {
                                    $u_image = '<div style="text-align:center;padding:5px;">' . $V->finish($V->get_var('output')) . '</div>';
                                } else {
                                    $u_image = '<div style="padding:5px;">' . $V->finish($V->get_var('output')) . '</div>';
                                }
                            }
                            break;
                        case 'application/x-shockwave-flash':
                            // set the default playback options...
                            $playback_options['play'] = $_MG_CONF['swf_play'];
                            $playback_options['menu'] = $_MG_CONF['swf_menu'];
                            $playback_options['quality'] = $_MG_CONF['swf_quality'];
                            $playback_options['height'] = $_MG_CONF['swf_height'];
                            $playback_options['width'] = $_MG_CONF['swf_width'];
                            $playback_options['loop'] = $_MG_CONF['swf_loop'];
                            $playback_options['scale'] = $_MG_CONF['swf_scale'];
                            $playback_options['wmode'] = $_MG_CONF['swf_wmode'];
                            $playback_options['allowscriptaccess'] = $_MG_CONF['swf_allowscriptaccess'];
                            $playback_options['bgcolor'] = $_MG_CONF['swf_bgcolor'];
                            $playback_options['swf_version'] = $_MG_CONF['swf_version'];
                            $playback_options['flashvars'] = $_MG_CONF['swf_flashvars'];
                            $poResult = DB_query("SELECT * FROM {$_TABLES['mg_playback_options']} WHERE media_id='" . $row['media_id'] . "'");
                            while ($poRow = DB_fetchArray($poResult)) {
                                $playback_options[$poRow['option_name']] = $poRow['option_value'];
                            }
                            if ($swfjsinclude > 0) {
                                $u_image = '';
                            } else {
                                $S = new Template(MG_getTemplatePath(0));
                                $S->set_file(array('swf' => 'swfobject.thtml'));
                                $S->set_var(array('site_url' => $_MG_CONF['site_url']));
                                $S->parse('output', 'swf');
                                $u_image = $S->finish($S->get_var('output'));
                                $swfjsinclude++;
                            }
                            $V = new Template(MG_getTemplatePath(0));
                            $V->set_file(array('video' => 'view_swf.thtml'));
                            $V->set_var(array('site_url' => $_MG_CONF['site_url'], 'lang_noflash' => $LANG_MG03['no_flash'], 'play' => $autoplay ? 'true' : 'false', 'menu' => $playback_options['menu'] ? 'true' : 'false', 'loop' => $playback_options['loop'] ? 'true' : 'false', 'scale' => $playback_options['scale'], 'wmode' => $playback_options['wmode'], 'flashvars' => $playback_options['flashvars'], 'quality' => $playback_options['quality'], 'height' => $videoheight, 'width' => $videowidth, 'asa' => $playback_options['allowscriptaccess'], 'bgcolor' => $playback_options['bgcolor'], 'swf_version' => $playback_options['swf_version'], 'filename' => $row['media_original_filename'], 'id' => $row['media_filename'] . rand(), 'id2' => $row['media_filename'] . rand(), 'movie' => $_MG_CONF['mediaobjects_url'] . '/orig/' . $row['media_filename'][0] . '/' . $row['media_filename'] . '.' . $row['media_mime_ext']));
                            $V->parse('output', 'video');
                            if ($align != '' && $align != "center") {
                                $u_image = '<div style="float:' . $align . ';padding:5px;">' . $V->finish($V->get_var('output')) . '</div>';
                            } else {
                                if ($align == "center") {
                                    $u_image = '<div style="text-align:center;padding:5px;">' . $V->finish($V->get_var('output')) . '</div>';
                                } else {
                                    $u_image = '<div style="padding:5px;">' . $V->finish($V->get_var('output')) . '</div>';
                                }
                            }
                            break;
                        case 'video/x-flv':
                            // set the default playback options...
                            $playback_options['play'] = $_MG_CONF['swf_play'];
                            $playback_options['menu'] = $_MG_CONF['swf_menu'];
                            $playback_options['quality'] = $_MG_CONF['swf_quality'];
                            $playback_options['height'] = $_MG_CONF['swf_height'];
                            $playback_options['width'] = $_MG_CONF['swf_width'];
                            $playback_options['loop'] = $_MG_CONF['swf_loop'];
                            $playback_options['scale'] = $_MG_CONF['swf_scale'];
                            $playback_options['wmode'] = $_MG_CONF['swf_wmode'];
                            $playback_options['allowscriptaccess'] = $_MG_CONF['swf_allowscriptaccess'];
                            $playback_options['bgcolor'] = $_MG_CONF['swf_bgcolor'];
                            $playback_options['swf_version'] = $_MG_CONF['swf_version'];
                            $playback_options['flashvars'] = $_MG_CONF['swf_flashvars'];
                            $poResult = DB_query("SELECT * FROM {$_TABLES['mg_playback_options']} WHERE media_id='" . $row['media_id'] . "'");
                            while ($poRow = DB_fetchArray($poResult)) {
                                $playback_options[$poRow['option_name']] = $poRow['option_value'];
                            }
                            if ($swfjsinclude > 0) {
                                $u_image = '';
                            } else {
                                $S = new Template(MG_getTemplatePath(0));
                                $S->set_file(array('swf' => 'swfobject.thtml'));
                                $S->set_var(array('site_url' => $_MG_CONF['site_url']));
                                $S->parse('output', 'swf');
                                $u_image = $S->finish($S->get_var('output'));
                                $swfjsinclude++;
                            }
                            $V = new Template(MG_getTemplatePath(0));
                            $V->set_file('video', 'view_flv_light.thtml');
                            $playImage = MG_getImageFile('blank_blk.jpg');
                            // now the player specific items.
                            $F = new Template(MG_getTemplatePath(0));
                            $F->set_file(array('player' => 'flvfp.thtml'));
                            if ($autoplay == 1) {
                                // auto start
                                $playButton = '';
                            } else {
                                if ($row['media_tn_attached'] == 1) {
                                    foreach ($_MG_CONF['validExtensions'] as $ext) {
                                        if (file_exists($_MG_CONF['path_mediaobjects'] . 'tn/' . $row['media_filename'][0] . '/tn_' . $row['media_filename'] . $ext)) {
                                            $playImage = $_MG_CONF['mediaobjects_url'] . '/tn/' . $row['media_filename'][0] . '/tn_' . $row['media_filename'] . $ext;
                                            break;
                                        }
                                    }
                                }
                                $playButton = "{ url: '" . $playImage . "', overlayId: 'play' },";
                            }
                            if ($row['remote_media'] == 1) {
                                $urlParts = array();
                                $urlParts = parse_url($row['remote_url']);
                                $pathParts = array();
                                $pathParts = explode('/', $urlParts['path']);
                                $ppCount = count($pathParts);
                                $pPath = '';
                                for ($row = 1; $row < $ppCount - 1; $row++) {
                                    $pPath .= '/' . $pathParts[$row];
                                }
                                $videoFile = $pathParts[$ppCount - 1];
                                $pos = strrpos($videoFile, '.');
                                if ($pos === false) {
                                    $basefilename = $videoFile;
                                } else {
                                    $basefilename = substr($videoFile, 0, $pos);
                                }
                                $videoFile = $basefilename;
                                $streamingServerURL = "streamingServerURL: '" . $urlParts['scheme'] . '://' . $urlParts['host'] . $pPath . "',";
                                $streamingServer = "streamingServer: 'fms',";
                            } else {
                                $streamingServerURL = '';
                                $streamingServer = '';
                                $videoFile = urlencode($_MG_CONF['mediaobjects_url'] . '/orig/' . $row['media_filename'][0] . '/' . $row['media_filename'] . '.' . $row['media_mime_ext']);
                            }
                            $width = $videowidth;
                            $height = $videoheight + 22;
                            $resolution_x = $videowidth;
                            $resolution_y = $videoheight;
                            $id = 'id_' . rand();
                            $id2 = 'id2_' . rand();
                            $F->set_var(array('site_url' => $_MG_CONF['site_url'], 'lang_noflash' => $LANG_MG03['no_flash'], 'play' => $autoplay ? 'true' : 'false', 'menu' => $playback_options['menu'] ? 'true' : 'false', 'loop' => $playback_options['loop'] ? 'true' : 'false', 'scale' => $playback_options['scale'], 'wmode' => $playback_options['wmode'], 'width' => $width, 'height' => $height, 'streamingServerURL' => $streamingServerURL, 'streamingServer' => $streamingServer, 'videoFile' => $videoFile, 'playButton' => $playButton, 'id' => $id, 'id2' => $id2, 'resolution_x' => $resolution_x, 'resolution_y' => $resolution_y));
                            $F->parse('output', 'player');
                            $flv_player = $F->finish($F->get_var('output'));
                            $V->set_var(array('site_url' => $_MG_CONF['site_url'], 'lang_noflash' => $LANG_MG03['no_flash'], 'id' => $id, 'id2' => $id2, 'width' => $resolution_x, 'height' => $resolution_y, 'flv_player' => $flv_player));
                            $V->parse('output', 'video');
                            if ($align != '' && $align != "center") {
                                $u_image .= '<span class="' . $classes . '" style="float:' . $align . ';padding:5px;">' . $V->finish($V->get_var('output')) . '</span>';
                            } else {
                                if ($align == "center") {
                                    $u_image .= '<span class="' . $classes . '" style="text-align:center;padding:5px;">' . $V->finish($V->get_var('output')) . '</span>';
                                } else {
                                    $u_image .= '<span class="' . $classes . '" style="padding:5px;">' . $V->finish($V->get_var('output')) . '</span>';
                                }
                            }
                            break;
                    }
                    $link = $u_image;
                    if ($destination != 'block') {
                        $content = str_replace($autotag['tagstr'], $link, $content);
                    } else {
                        $autoTagCount = $mgAutoTagArray['count'];
                        $mgAutoTagArray['tags'][$autoTagCount] = $link;
                        $mgAutoTagArray['count']++;
                        $link = '';
                        $content = str_replace($autotag['tagstr'], $link, $content);
                    }
                    return $content;
                } else {
                    $link = '';
                    $content = str_replace($autotag['tagstr'], $link, $content);
                    return $content;
                }
                break;
            case 'audio':
                $sql = "SELECT ma.album_id,m.media_title,m.mime_type,m.media_tn_attached,m.media_filename,m.media_mime_ext FROM {$_TABLES['mg_media']} AS m LEFT JOIN {$_TABLES['mg_media_albums']} AS ma ON m.media_id=ma.media_id WHERE m.media_id='" . DB_escapeString($parm1) . "'";
                $result = DB_query($sql);
                if (DB_numRows($result) > 0) {
                    $row = DB_fetchArray($result);
                    $aid = $row['album_id'];
                    if (!isset($MG_albums[$aid]->id) || $MG_albums[$aid]->access == 0) {
                        $link = '';
                        $content = str_replace($autotag['tagstr'], $link, $content);
                        return $content;
                    }
                    switch ($row['mime_type']) {
                        case 'audio/mpeg':
                            $playback_options['height'] = 50;
                            $playback_options['width'] = 300;
                            $V = new Template(MG_getTemplatePath(0));
                            if ($mp3_type == 'ribbon') {
                                $tfile = 'mp3_podcast.thtml';
                            } else {
                                $tfile = 'view_mp3_flv.thtml';
                            }
                            $autostart = $autoplay ? 'play' : 'stop';
                            if ($row['media_tn_attached'] == 1) {
                                foreach ($_MG_CONF['validExtensions'] as $ext) {
                                    if (file_exists($_MG_CONF['path_mediaobjects'] . 'tn/' . $row['media_filename'][0] . '/tn_' . $row['media_filename'] . $ext)) {
                                        $u_tn = $_MG_CONF['mediaobjects_url'] . '/tn/' . $row['media_filename'][0] . '/tn_' . $row['media_filename'] . $ext;
                                        $media_size_disp = @getimagesize($_MG_CONF['path_mediaobjects'] . 'tn/' . $row['media_filename'][0] . '/tn_' . $row['media_filename'] . $ext);
                                        break;
                                    }
                                }
                                $border_width = $media_size_disp[0] + 15;
                                $u_pic = '<img src="' . $u_tn . '" alt="" style="border:none;" />';
                                $playback_options['width'] = 200;
                            } else {
                                $u_pic = '';
                                $playback_options['width'] = 200;
                            }
                            $V->set_file(array('audio' => $tfile));
                            $V->set_var(array('autostart' => $autostart, 'enablecontextmenu' => 'true', 'stretchtofit' => 'false', 'showstatusbar' => 'true', 'uimode' => 'mini', 'height' => $playback_options['height'], 'width' => $playback_options['width'], 'bgcolor' => '#FFFFFF', 'loop' => 'true', 'u_pic' => $u_pic, 'title' => urlencode($row['media_title']), 'id' => 'mp3' . rand(), 'id2' => 'mp3' . rand(), 'site_url' => $_MG_CONF['site_url'], 'movie' => $_MG_CONF['mediaobjects_url'] . '/orig/' . $row['media_filename'][0] . '/' . $row['media_filename'] . '.' . $row['media_mime_ext'], 'mp3_file' => $_MG_CONF['mediaobjects_url'] . '/orig/' . $row['media_filename'][0] . '/' . $row['media_filename'] . '.' . $row['media_mime_ext']));
                            $V->parse('output', 'audio');
                            if ($align != '' && $align != "center") {
                                $u_image = '<span style="float:' . $align . ';padding:5px;text-align:center;">' . $V->finish($V->get_var('output')) . '</span>';
                            } else {
                                if ($align == "center") {
                                    $u_image = '<span style="text-align:center;padding:5px;text-align:center;">' . $V->finish($V->get_var('output')) . '</span>';
                                } else {
                                    $u_image = '<span style="padding:5px;text-align:center;">' . $V->finish($V->get_var('output')) . '</span>';
                                }
                            }
                            break;
                        case 'audio/x-ms-wma':
                        case 'audio/x-ms-wax':
                        case 'audio/x-ms-wmv':
                            $playback_options['height'] = 50;
                            $playback_options['width'] = 300;
                            $V = new Template(MG_getTemplatePath(0));
                            $tfile = 'view_mp3_wmp.thtml';
                            $autostart = $autoplay ? '1' : '0';
                            if ($row['media_tn_attached'] == 1) {
                                foreach ($_MG_CONF['validExtensions'] as $ext) {
                                    if (file_exists($_MG_CONF['path_mediaobjects'] . 'tn/' . $row['media_filename'][0] . '/tn_' . $row['media_filename'] . $ext)) {
                                        $u_tn = $_MG_CONF['mediaobjects_url'] . '/tn/' . $row['media_filename'][0] . '/tn_' . $row['media_filename'] . $ext;
                                        $media_size_disp = @getimagesize($_MG_CONF['path_mediaobjects'] . 'tn/' . $row['media_filename'][0] . '/tn_' . $row['media_filename'] . $ext);
                                        break;
                                    }
                                }
                                $border_width = $media_size_disp[0] + 15;
                                $u_pic = '<div class=out style="width:' . $border_width . 'px"><div class="in ltin tpin"><img src="' . $u_tn . '" alt="" /></div></div>';
                                $playback_options['height'] = 50;
                                $playback_options['width'] = 200;
                            } else {
                                $u_pic = '';
                                $playback_options['height'] = 50;
                                $playback_options['width'] = 200;
                            }
                            $V->set_file(array('audio' => $tfile));
                            $V->set_var(array('autostart' => $autostart, 'enablecontextmenu' => 'true', 'stretchtofit' => 'false', 'showstatusbar' => 'true', 'uimode' => 'mini', 'height' => $playback_options['height'], 'width' => $playback_options['width'], 'bgcolor' => '#FFFFFF', 'loop' => 'true', 'u_pic' => $u_pic, 'movie' => $_MG_CONF['mediaobjects_url'] . '/orig/' . $row['media_filename'][0] . '/' . $row['media_filename'] . '.' . $row['media_mime_ext']));
                            $V->parse('output', 'audio');
                            if ($align != '' && $align != "center") {
                                $u_image = '<div class="' . $classes . '" style="float:' . $align . ';padding:5px;">' . $V->finish($V->get_var('output')) . '</div>';
                            } else {
                                if ($align == "center") {
                                    $u_image = '<div class="' . $classes . '" style="text-align:center;padding:5px;">' . $V->finish($V->get_var('output')) . '</div>';
                                } else {
                                    $u_image = '<div class="' . $classes . '" style="padding:5px;">' . $V->finish($V->get_var('output')) . '</div>';
                                }
                            }
                            break;
                    }
                    $link = $u_image;
                    if ($destination != 'block') {
                        $content = str_replace($autotag['tagstr'], $link, $content);
                    } else {
                        $autoTagCount = $mgAutoTagArray['count'];
                        $mgAutoTagArray['tags'][$autoTagCount] = $link;
                        $mgAutoTagArray['count']++;
                        $link = '';
                        $content = str_replace($autotag['tagstr'], $link, $content);
                    }
                    return $content;
                } else {
                    $link = '';
                    $content = str_replace($autotag['tagstr'], $link, $content);
                    return $content;
                }
                break;
            case 'fslideshow':
                if ($parm1 == '' || $parm1 == 0) {
                    return $content;
                }
                $aid = $parm1;
                if (!isset($MG_albums[$parm1]->id) || $MG_albums[$parm1]->access == 0) {
                    $link = '';
                    $content = str_replace($autotag['tagstr'], $link, $content);
                    return $content;
                }
                if ($width > 0 && $height == 0) {
                    $height = $width * 0.75;
                } else {
                    if ($width == 0 && $height == 0) {
                        $height = $width = 200;
                    } else {
                        if ($width == 0 && $height > 0) {
                            $width = $height * 1.3333;
                        }
                    }
                }
                // if none of the above, assume height and width both specified.
                if ($caption == '' && $_MG_CONF['autotag_caption'] && isset($aid)) {
                    $caption = $MG_albums[$aid]->title;
                }
                $captionHTML = '<br /><span style="width:' . $width . 'px;font-style:italic;font-size: smaller;text-indent:0;">' . $caption . '</span>' . LB;
                $ss_count++;
                $T = new Template(MG_getTemplatePath(0));
                $T->set_file(array('fslideshow' => 'fsat.thtml'));
                $T->set_var(array('site_url' => $_MG_CONF['site_url']));
                $T->set_var(array('id' => 'mms' . $ss_count, 'id2' => 'fsid' . $ss_count, 'movie' => $_MG_CONF['site_url'] . '/xml.php?aid=' . $parm1 . '%26src=' . trim($src), 'dropshadow' => 'true', 'delay' => $delay, 'nolink' => $MG_albums[$parm1]->hidden || $enable_link == 0 ? 'true' : 'false', 'showtitle' => $showtitle == 'bottom' || $showtitle == 'top' ? '&showTitle=' . $showtitle : '', 'width' => $width, 'height' => $height));
                $T->parse('output', 'fslideshow');
                $swfobject = $T->finish($T->get_var('output'));
                $link = $swfobject . $captionHTML;
                if ($align != '' && $align != "center") {
                    $link = '<span class="' . $classes . '" style="float:' . $align . ';padding:5px;text-align:center;">' . $link . '</span>';
                } else {
                    if ($align == "center") {
                        $link = '<center><span class="' . $classes . '" style="padding:5px;text-align:center;">' . $link . '</span></center>';
                    } else {
                        $link = '<span class="' . $classes . '" style="padding:5px;text-align:center;">' . $link . '</span>';
                    }
                }
                if ($destination != 'block') {
                    $content = str_replace($autotag['tagstr'], $link, $content);
                } else {
                    $autoTagCount = $mgAutoTagArray['count'];
                    $mgAutoTagArray['tags'][$autoTagCount] = $link;
                    $mgAutoTagArray['count']++;
                    $link = '';
                    $content = str_replace($autotag['tagstr'], $link, $content);
                }
                return $content;
                break;
            case 'slideshow':
                if ($parm1 == '' || $parm1 == 0) {
                    return $content;
                }
                if (!isset($MG_albums[$parm1]->id) || $MG_albums[$parm1]->access == 0) {
                    $link = '';
                    $content = str_replace($autotag['tagstr'], $link, $content);
                    return $content;
                }
                if ($caption == '' && $_MG_CONF['autotag_caption']) {
                    $caption = $MG_albums[$parm1]->title;
                }
                $T->set_file(array('tag' => 'autotag_ss.thtml'));
                $aid = $parm1;
                $pics = '';
                $counter = 0;
                $maxwidth = 0;
                $maxheight = 0;
                $ss_count++;
                $sql = "SELECT m.media_filename,m.media_mime_ext,m.remote_url FROM {$_TABLES['mg_media_albums']} as ma INNER JOIN " . $_TABLES['mg_media'] . " as m " . " ON ma.media_id=m.media_id WHERE ma.album_id='" . DB_escapeString($aid) . "' AND m.media_type=0 AND m.include_ss=1 ORDER BY ma.media_order DESC";
                $result = DB_query($sql);
                $T->set_block('tag', 'slides', 'ss');
                while ($row = DB_fetchArray($result)) {
                    switch ($src) {
                        case 'orig':
                            $media_size = @getimagesize($_MG_CONF['path_mediaobjects'] . 'orig/' . $row['media_filename'][0] . '/' . $row['media_filename'] . '.' . $row['media_mime_ext']);
                            $ext = $row['media_mime_ext'];
                            break;
                        case 'disp':
                            foreach ($_MG_CONF['validExtensions'] as $tnext) {
                                if (file_exists($_MG_CONF['path_mediaobjects'] . 'disp/' . $row['media_filename'][0] . '/' . $row['media_filename'] . $tnext)) {
                                    $media_size = @getimagesize($_MG_CONF['path_mediaobjects'] . 'disp/' . $row['media_filename'][0] . '/' . $row['media_filename'] . $tnext);
                                    $ext = substr($tnext, 1, 3);
                                    break;
                                }
                            }
                            break;
                        default:
                            foreach ($_MG_CONF['validExtensions'] as $tnext) {
                                if (file_exists($_MG_CONF['path_mediaobjects'] . 'tn/' . $row['media_filename'][0] . '/' . $row['media_filename'] . $tnext)) {
                                    $media_size = @getimagesize($_MG_CONF['path_mediaobjects'] . 'tn/' . $row['media_filename'][0] . '/' . $row['media_filename'] . $tnext);
                                    $ext = substr($tnext, 1, 3);
                                    break;
                                }
                            }
                            $src = 'tn';
                            break;
                    }
                    if ($media_size == false) {
                        continue;
                    }
                    $counter++;
                    if ($width > 0 && $height == 0) {
                        if ($media_size[0] > $media_size[1]) {
                            // landscape
                            $ratio = $media_size[0] / $width;
                            $newwidth = $width;
                            $newheight = round($media_size[1] / $ratio);
                        } else {
                            // portrait
                            $ratio = $media_size[1] / $width;
                            $newheight = $width;
                            $newwidth = round($media_size[0] / $ratio);
                        }
                    } else {
                        if ($width == 0 && $height == 0) {
                            if ($media_size[0] > $media_size[1]) {
                                // landscape
                                $ratio = $media_size[0] / 200;
                                $newwidth = 200;
                                $newheight = round($media_size[1] / $ratio);
                            } else {
                                // portrait
                                $ratio = $media_size[1] / 200;
                                $newheight = 200;
                                $newwidth = round($media_size[0] / $ratio);
                            }
                        } else {
                            if ($width == 0 && $height > 0) {
                                if ($height > $media_size[1]) {
                                    $newheight = $media_size[1];
                                    $newwidth = $media_size[0];
                                } else {
                                    $ratio = $height / $media_size[1];
                                    $newheight = $height;
                                    $newwidth = round($media_size[0] * $ratio);
                                }
                            } else {
                                $newwidth = $width;
                                $newheight = $height;
                            }
                        }
                    }
                    if ($newheight > $maxheight) {
                        $maxheight = $newheight;
                    }
                    if ($newwidth > $maxwidth) {
                        $maxwidth = $newwidth;
                    }
                    $active = '';
                    if ($counter == 1) {
                        $active = ' active ';
                    }
                    if ($MG_albums[$parm1]->hidden == 1 || $enable_link == 0) {
                        $pics .= '<img class="slideshowThumbnail' . $ss_count . $active . ' ' . $classes . '" src="' . $_MG_CONF['mediaobjects_url'] . '/' . $src . '/' . $row['media_filename'][0] . '/' . $row['media_filename'] . '.' . $ext . '" alt="" style="width:' . $newwidth . 'px;height:' . $newheight . 'px;border:none;position:absolute;left:0px;top:0px;" />' . LB;
                    } else {
                        $pics .= '<img class="slideshowThumbnail' . $ss_count . $active . ' ' . $classes . '". src="' . $_MG_CONF['mediaobjects_url'] . '/' . $src . '/' . $row['media_filename'][0] . '/' . $row['media_filename'] . '.' . $ext . '" alt="" style="width:' . $newwidth . 'px;height:' . $newheight . 'px;border:none;position:absolute;left:0px;top:0px;" />' . LB;
                    }
                    $T->set_var(array('img_url' => $_MG_CONF['mediaobjects_url'] . '/' . $src . '/' . $row['media_filename'][0] . '/' . $row['media_filename'] . '.' . $ext, 'img_width' => $newwidth, 'img_height' => $newheight));
                    $T->parse('ss', 'slides', true);
                }
                if ($delay <= 0) {
                    $delay = 10;
                }
                if ($MG_albums[$parm1]->hidden == 1 || $enable_link == 0) {
                    $ss_url = '';
                } else {
                    $ss_url = '<a href="' . $_MG_CONF['site_url'] . '/album.php?aid=' . $aid . '"' . ($target == '' ? '' : ' target="' . $target . '"') . '>';
                    $ss_url = $_MG_CONF['site_url'] . '/album.php?aid=' . $aid;
                }
                if ($counter != 0) {
                    $T->set_var(array('align' => $align, 'pics' => $pics, 'caption' => $caption, 'maxheight' => $maxheight, 'maxwidth' => $maxwidth, 'width' => $maxwidth, 'framewidth' => $maxwidth + 10, 'ss_count' => $ss_count, 'delay' => $delay * 1000, 'border' => $border ? 'border: silver solid;border-width: 1px;' : '', 'sslink' => $ss_url));
                    if ($align == 'left' || $align == 'right') {
                        $T->set_var('float', 'float: ' . $align . ';');
                    } else {
                        $T->set_var('float', 'float:left;');
                        $align = 'left';
                    }
                    if ($align == 'left') {
                        $T->set_var('margin-right', 'margin-right:15px;');
                    } else {
                        $T->set_var('margin-right', '');
                    }
                    $T->parse('output', 'tag');
                    $link = $T->finish($T->get_var('output'));
                } else {
                    $link = '';
                }
                if ($destination != 'block') {
                    $content = str_replace($autotag['tagstr'], $link, $content);
                } else {
                    $autoTagCount = $mgAutoTagArray['count'];
                    $mgAutoTagArray['tags'][$autoTagCount] = $link;
                    $mgAutoTagArray['count']++;
                    $link = '';
                    $content = str_replace($autotag['tagstr'], $link, $content);
                }
                return $content;
                break;
            case 'album':
                if ($parm1 == '' || $parm1 == 0) {
                    $side_count--;
                    return $content;
                }
                if (!isset($MG_albums[$parm1]->id) || $MG_albums[$parm1]->access == 0) {
                    $link = '';
                    $content = str_replace($autotag['tagstr'], $link, $content);
                    $side_count--;
                    return $content;
                }
                $ss_count++;
                if ($border == 0) {
                    $T->set_file(array('tag' => 'autotag_nb.thtml'));
                } else {
                    $T->set_file(array('tag' => 'autotag.thtml'));
                }
                if ($tag != '') {
                    $alttag = ' alt="' . $tag . '" title="' . $tag . '"';
                } else {
                    $alttag = ' alt=""';
                    if ($_MG_CONF['autotag_caption']) {
                        $caption = $MG_albums[$parm1]->title;
                    }
                }
                $aid = $parm1;
                if ($MG_albums[$parm1]->tn_attached == 1) {
                    foreach ($_MG_CONF['validExtensions'] as $ext) {
                        if (file_exists($_MG_CONF['path_mediaobjects'] . 'covers/cover_' . $parm1 . $ext)) {
                            $tnImage = $_MG_CONF['mediaobjects_url'] . '/covers/cover_' . $parm1 . $ext;
                            $tnFileName = $_MG_CONF['path_mediaobjects'] . 'covers/cover_' . $parm1 . $ext;
                            break;
                        }
                    }
                } else {
                    $filename = $MG_albums[$aid]->findCover();
                    if ($filename != '') {
                        foreach ($_MG_CONF['validExtensions'] as $ext) {
                            if (file_exists($_MG_CONF['path_mediaobjects'] . 'tn/' . $filename[0] . '/' . $filename . $ext)) {
                                $tnImage = $_MG_CONF['mediaobjects_url'] . '/tn/' . $filename[0] . '/' . $filename . $ext;
                                $tnFileName = $_MG_CONF['path_mediaobjects'] . 'tn/' . $filename[0] . '/' . $filename . $ext;
                                break;
                            }
                        }
                    } else {
                        $tnImage = $_MG_CONF['mediaobjects_url'] . '/placeholder.svg';
                        $tnFileName = $_MG_CONF['path_mediaobjects'] . 'placeholder.svg';
                    }
                }
                $media_size = @getimagesize($tnFileName);
                if ($media_size == false) {
                    $tnImage = $_MG_CONF['mediaobjects_url'] . '/placeholder.svg';
                    $tnFileName = $_MG_CONF['path_mediaobjects'] . 'placeholder.svg';
                    $media_size = array(200, 200);
                }
                if ($width > 0 && $height == 0) {
                    $ratio = $media_size[0] / $width;
                    $newwidth = $width;
                    $newheight = round($media_size[1] / $ratio);
                } else {
                    if ($width == 0 && $height == 0) {
                        if ($media_size[0] > $media_size[1]) {
                            // landscape
                            $ratio = $media_size[0] / 200;
                            $newwidth = 200;
                            $newheight = round($media_size[1] / $ratio);
                        } else {
                            // portrait
                            $ratio = $media_size[1] / 200;
                            $newheight = 200;
                            $newwidth = round($media_size[0] / $ratio);
                        }
                    } else {
                        if ($width == 0 && $height > 0) {
                            $ratio = $height / $media_size[1];
                            $newheight = $height;
                            $newwidth = round($media_size[0] * $ratio);
                        } else {
                            $newwidth = $width;
                            $newheight = $height;
                        }
                    }
                }
                $album_image = '<img src="' . $tnImage . '" ' . $alttag . ' style="';
                if ($nosize == 0 && $height != -1 && $width != -1) {
                    $album_image .= 'width:' . $newwidth . 'px;height:' . $newheight . 'px;';
                }
                $album_image .= 'border:none;" />';
                $tagtext = $album_image;
                if ($linkID == 0) {
                    $url = $_MG_CONF['site_url'] . '/album.php?aid=' . $parm1;
                } else {
                    if ($linkID < 1000000) {
                        $url = $_MG_CONF['site_url'] . '/album.php?aid=' . $linkID;
                    } else {
                        $url = $_MG_CONF['site_url'] . '/media.php?s=' . $linkID;
                    }
                }
                if ($enable_link == 0) {
                    $link = $tagtext;
                } else {
                    $link = '<a href="' . $url . '"' . ($target == '' ? '' : ' target="' . $target . '"') . '>' . $tagtext . '</a>';
                }
                $T->set_var(array('ss_count' => $ss_count, 'align' => $align, 'autotag' => $link, 'caption' => $caption, 'width' => $newwidth, 'framewidth' => $newwidth + 10));
                if ($align == 'left' || $align == 'right') {
                    $T->set_var('float', 'float:' . $align . ';');
                } else {
                    $T->set_var('float', '');
                }
                if ($align == 'left') {
                    $T->set_var('margin-right', 'margin-right:15px;');
                } else {
                    $T->set_var('margin-right', '');
                }
                $T->parse('output', 'tag');
                $link = $T->finish($T->get_var('output'));
                if ($align == 'center') {
                    $link = '<center>' . $link . '</center>';
                }
                if ($destination != 'block') {
                    $content = str_replace($autotag['tagstr'], $link, $content);
                } else {
                    $autoTagCount = $mgAutoTagArray['count'];
                    $mgAutoTagArray['tags'][$autoTagCount] = $link;
                    $mgAutoTagArray['count']++;
                    $link = '';
                    $content = str_replace($autotag['tagstr'], $link, $content);
                }
                return $content;
                break;
            case 'alink':
                if ($parm1 == '' || $parm1 == 0) {
                    $side_count--;
                    return $content;
                }
                if (!isset($MG_albums[$parm1]->id) || $MG_albums[$parm1]->access == 0) {
                    $link = '';
                    $content = str_replace($autotag['tagstr'], $link, $content);
                    $side_count--;
                    return $content;
                }
                if ($caption == '') {
                    $caption = $MG_albums[$parm1]->title;
                }
                $link = '<a href="' . $_MG_CONF['site_url'] . '/album.php?aid=' . $MG_albums[$parm1]->id . '">' . $caption . '</a>';
                $content = str_replace($autotag['tagstr'], $link, $content);
                return $content;
                break;
            case 'media':
                /* image, oimage and img are depreciated */
            /* image, oimage and img are depreciated */
            case 'image':
            case 'oimage':
            case 'img':
                if ($parm1 == '' || $parm1 == 0) {
                    return $content;
                }
                $direct_link = '';
                $ss_count++;
                if ($border == 0) {
                    $T->set_file(array('tag' => 'autotag_nb.thtml'));
                } else {
                    $T->set_file(array('tag' => 'autotag.thtml'));
                }
                if ($tag != '') {
                    $alttag = ' alt="' . $tag . '" title="' . $tag . '"';
                } else {
                    $alttag = ' alt=""';
                }
                $sql = "SELECT ma.album_id,m.media_title,m.media_type,m.media_filename,m.media_mime_ext,m.mime_type,m.media_tn_attached,m.remote_url FROM {$_TABLES['mg_media']} AS m LEFT JOIN {$_TABLES['mg_media_albums']} AS ma ON m.media_id=ma.media_id WHERE m.media_id='" . DB_escapeString($parm1) . "'";
                $result = DB_query($sql);
                if (DB_numRows($result) > 0) {
                    $row = DB_fetchArray($result);
                    $aid = $row['album_id'];
                    if (!isset($MG_albums[$aid]->id) || $MG_albums[$aid]->access == 0) {
                        $link = '';
                        $content = str_replace($autotag['tagstr'], $link, $content);
                        return $content;
                    }
                    if ($caption == '' && $_MG_CONF['autotag_caption']) {
                        $caption = $row['media_title'];
                    }
                    switch ($row['media_type']) {
                        case 0:
                            // standard image
                            if ($autotag['tag'] == 'oimage') {
                                if ($_MG_CONF['discard_originals'] == 1) {
                                    $default_thumbnail = 'disp/' . $row['media_filename'][0] . '/' . $row['media_filename'] . '.' . $row['media_mime_ext'];
                                } else {
                                    $default_thumbnail = 'orig/' . $row['media_filename'][0] . '/' . $row['media_filename'] . '.' . $row['media_mime_ext'];
                                }
                            } else {
                                switch ($src) {
                                    case 'orig':
                                        if ($_MG_CONF['discard_originals'] == 1) {
                                            $default_thumbnail = 'disp/' . $row['media_filename'][0] . '/' . $row['media_filename'] . '.' . $row['media_mime_ext'];
                                        } else {
                                            $default_thumbnail = 'orig/' . $row['media_filename'][0] . '/' . $row['media_filename'] . '.' . $row['media_mime_ext'];
                                        }
                                        break;
                                    case 'disp':
                                        $default_thumbnail = 'disp/' . $row['media_filename'][0] . '/' . $row['media_filename'] . '.' . $row['media_mime_ext'];
                                        break;
                                    case 'tn':
                                        foreach ($_MG_CONF['validExtensions'] as $ext) {
                                            if (file_exists($_MG_CONF['path_mediaobjects'] . 'tn/' . $row['media_filename'][0] . '/' . $row['media_filename'] . $ext)) {
                                                $default_thumbnail = 'tn/' . $row['media_filename'][0] . '/' . $row['media_filename'] . $ext;
                                                break;
                                            }
                                        }
                                        break;
                                    default:
                                        foreach ($_MG_CONF['validExtensions'] as $ext) {
                                            if (file_exists($_MG_CONF['path_mediaobjects'] . 'tn/' . $row['media_filename'][0] . '/' . $row['media_filename'] . $ext)) {
                                                $default_thumbnail = 'tn/' . $row['media_filename'][0] . '/' . $row['media_filename'] . $ext;
                                                break;
                                            }
                                        }
                                        break;
                                }
                                foreach ($_MG_CONF['validExtensions'] as $ext) {
                                    if (file_exists($_MG_CONF['path_mediaobjects'] . $link_src . '/' . $row['media_filename'][0] . '/' . $row['media_filename'] . $ext)) {
                                        $direct_link = $_MG_CONF['mediaobjects_url'] . '/' . $link_src . '/' . $row['media_filename'][0] . '/' . $row['media_filename'] . $ext;
                                        break;
                                    }
                                }
                            }
                            break;
                        case 1:
                            // video file
                            switch ($row['mime_type']) {
                                case 'application/x-shockwave-flash':
                                    $default_thumbnail = 'flash.png';
                                    break;
                                case 'video/quicktime':
                                case 'video/mpeg':
                                case 'video/x-m4v':
                                    $default_thumbnail = 'quicktime.png';
                                    break;
                                case 'video/x-ms-asf':
                                case 'video/x-ms-wvx':
                                case 'video/x-ms-wm':
                                case 'video/x-ms-wmx':
                                case 'video/x-msvideo':
                                case 'application/x-ms-wmz':
                                case 'application/x-ms-wmd':
                                    $default_thumbnail = 'wmp.png';
                                    break;
                                default:
                                    $default_thumbnail = 'video.png';
                                    break;
                            }
                            $src = 'tn';
                            break;
                        case 2:
                            // music file
                            $src = 'tn';
                            $default_thumbnail = 'audio.png';
                            break;
                    }
                    if ($row['media_tn_attached'] == 1 && ($src != 'orig' && $src != 'disp')) {
                        foreach ($_MG_CONF['validExtensions'] as $ext) {
                            if (file_exists($_MG_CONF['path_mediaobjects'] . 'tn/' . $row['media_filename'][0] . '/tn_' . $row['media_filename'] . $ext)) {
                                $media_thumbnail = $_MG_CONF['mediaobjects_url'] . '/tn/' . $row['media_filename'][0] . '/tn_' . $row['media_filename'] . $ext;
                                $media_thumbnail_file = $_MG_CONF['path_mediaobjects'] . 'tn/' . $row['media_filename'][0] . '/tn_' . $row['media_filename'] . $ext;
                                break;
                            }
                        }
                    } else {
                        $media_thumbnail = $_MG_CONF['mediaobjects_url'] . '/' . $default_thumbnail;
                        $media_thumbnail_file = $_MG_CONF['path_mediaobjects'] . $default_thumbnail;
                    }
                    if ($autotag['tag'] == 'img') {
                        if ($align != '' && $align != 'center') {
                            $album_image = '<span class="' . $classes . '" style="float:' . $align . ';padding:5px;"><img src="' . $media_thumbnail . '" ' . $alttag . 'style="border:none;" /></span>';
                        } else {
                            $album_image = '<img class="' . $classes . '" src="' . $media_thumbnail . '" ' . $alttag . 'style="border:none;" />';
                        }
                    } else {
                        $album_image = '<img class="' . $classes . '" src="' . $media_thumbnail . '" ' . $alttag . 'style="border:none;" />';
                    }
                } else {
                    return $content;
                    // no image found
                }
                $mediaSize = @getimagesize($media_thumbnail_file);
                if ($mediaSize == false) {
                    $link = '';
                    $content = str_replace($autotag['tagstr'], $link, $content);
                    return $content;
                }
                if ($autotag['tag'] == 'oimage' || $src == 'orig') {
                    $newwidth = $mediaSize[0];
                    $newheight = $mediaSize[1];
                } else {
                    if ($width > 0) {
                        $tn_height = $width;
                    } else {
                        switch ($src) {
                            case 'orig':
                                $tn_height = $mediaSize[0];
                                break;
                            case 'disp':
                                $tn_height = $mediaSize[0];
                                break;
                            case 'tn':
                                $tn_height = 200;
                                break;
                            default:
                                $tn_height = 200;
                                break;
                        }
                    }
                    if ($mediaSize[0] > $mediaSize[1]) {
                        $ratio = $mediaSize[0] / $tn_height;
                        $newwidth = $tn_height;
                        $newheight = round($mediaSize[1] / $ratio);
                    } else {
                        $ratio = $mediaSize[1] / $tn_height;
                        $newheight = $tn_height;
                        $newwidth = round($mediaSize[0] / $ratio);
                    }
                }
                $album_image = '<img class="' . $classes . '" src="' . $media_thumbnail . '" ' . $alttag . ' style=';
                if ($nosize == 0 && $height != -1 && $width != -1) {
                    $album_image .= '"width:' . $newwidth . 'px;height:' . $newheight . 'px;';
                }
                $album_image .= 'border:none;" />';
                $tagtext = $album_image;
                $link = '';
                if ($alt == 1 && $row['remote_url'] != '') {
                    $url = $row['remote_url'];
                    if ($autotag['tag'] != 'image' && $enable_link != 0) {
                        $link = '<a href="' . $url . '"' . ($target == '' ? '' : ' target="' . $target . '"') . '>' . $tagtext . '</a>';
                    } else {
                        $link = $tagtext;
                    }
                } else {
                    if ($linkID == 0) {
                        $url = $_MG_CONF['site_url'] . '/media.php?s=' . $parm1;
                    } else {
                        if ($linkID < 1000000) {
                            if (isset($MG_albums[$linkID]->id)) {
                                $url = $_MG_CONF['site_url'] . '/album.php?aid=' . $linkID;
                                if ($autotag['tag'] != 'image' && $MG_albums[$linkID]->hidden != 1 && $enable_link != 0) {
                                    $link = '<a href="' . $url . '"' . ($target == '' ? '' : ' target="' . $target . '"') . '>' . $tagtext . '</a>';
                                } else {
                                    $link = $tagtext;
                                }
                            } else {
                                $url = $_MG_CONF['site_url'] . '/media.php?s=' . $parm1;
                            }
                        } else {
                            $linkAID = (int) DB_getItem($_TABLES['mg_media_albums'], 'album_id', 'media_id="' . DB_escapeString($linkID) . '"');
                            if ($linkAID != 0) {
                                $url = $_MG_CONF['site_url'] . '/media.php?s=' . $linkID;
                                if ($autotag['tag'] != 'image' && $MG_albums[$linkAID]->hidden != 1 && $enable_link != 0) {
                                    $link = '<a href="' . $url . '"' . ($target == '' ? '' : ' target="' . $target . '"') . '>' . $tagtext . '</a>';
                                } else {
                                    $link = $tagtext;
                                }
                            } else {
                                $url = $_MG_CONF['site_url'] . '/media.php?s=' . $parm1;
                            }
                        }
                    }
                }
                if ($link == '') {
                    if ($autotag['tag'] != 'image' && ($MG_albums[$aid]->hidden != 1 || $enable_link == 2) && $enable_link != 0) {
                        if ($enable_link == 2 && $direct_link != '') {
                            if ($_MG_CONF['disable_lightbox'] == true) {
                                $link = $tagtext;
                            } else {
                                $link = '<a href="' . $direct_link . '" rel="lightbox" data-uk-lightbox title="' . strip_tags(str_replace('$', '&#36;', $caption)) . '">' . $tagtext . '</a>';
                            }
                        } else {
                            $link = '<a href="' . $url . '"' . ($target == '' ? '' : ' target="' . $target . '"') . '>' . $tagtext . '</a>';
                        }
                    } else {
                        $link = $tagtext;
                    }
                }
                if ($autotag['tag'] == 'img') {
                    if ($align != '' && $align != 'center') {
                        $link = '<span class="' . $classes . '" style="float:' . $align . ';padding:5px;">' . $link . '</span>';
                    }
                    if ($destination != 'block') {
                        $content = str_replace($autotag['tagstr'], $link, $content);
                    } else {
                        $autoTagCount = $mgAutoTagArray['count'];
                        $mgAutoTagArray['tags'][$autoTagCount] = $link;
                        $mgAutoTagArray['count']++;
                        $link = '';
                        $content = str_replace($autotag['tagstr'], $link, $content);
                    }
                    return $content;
                }
                $T->set_var(array('ss_count' => $ss_count, 'align' => $align, 'autotag' => $link, 'caption' => $caption, 'width' => $newwidth, 'framewidth' => $newwidth + 10));
                if ($align == 'left' || $align == 'right') {
                    $T->set_var('float', 'float:' . $align . ';');
                } else {
                    $T->set_var('float', '');
                }
                if ($align == 'left') {
                    $T->set_var('margin-right', 'margin-right:15px;');
                } else {
                    $T->set_var('margin-right', '');
                }
                $T->parse('output', 'tag');
                $link = $T->finish($T->get_var('output'));
                if ($align == 'center') {
                    $link = '<center>' . $link . '</center>';
                }
                if ($destination != 'block') {
                    $content = str_replace($autotag['tagstr'], $link, $content);
                } else {
                    $autoTagCount = $mgAutoTagArray['count'];
                    $mgAutoTagArray['tags'][$autoTagCount] = $link;
                    $mgAutoTagArray['count']++;
                    $link = '';
                    $content = str_replace($autotag['tagstr'], $link, $content);
                }
                return $content;
                break;
        }
    }
}
コード例 #5
0
ファイル: climport.php プロジェクト: spacequad/glfusion
function _MG_getFile($filename, $file, $albums, $caption = '', $description = '', $upload = 1, $purgefiles = 0, $filetype, $atttn, $thumbnail, $keywords = '', $category = 0, $dnc = 0, $replace = 0, $userid)
{
    global $MG_albums, $_CONF, $_MG_CONF, $_USER, $_TABLES, $LANG_MG00, $LANG_MG01, $LANG_MG02, $new_media_id;
    $artist = '';
    $musicAlbum = '';
    $genre = '';
    $video_attached_thumbnail = 0;
    $successfulWatermark = 0;
    $dnc = 1;
    $errors = 0;
    $errMsg = '';
    clearstatcache();
    if (!file_exists($filename)) {
        $errMsg = $LANG_MG02['upload_not_found'];
        return array(false, $errMsg);
    }
    clearstatcache();
    if (!is_readable($filename)) {
        $errMsg = $LANG_MG02['upload_not_readable'];
        return array(false, $errMsg);
    }
    // make sure we have the proper permissions to upload to this album....
    if (!isset($MG_albums[$albums]->id)) {
        $errMsg = $LANG_MG02['album_nonexist'];
        // "Album does not exist, unable to process uploads";
        return array(false, $errMsg);
    }
    sleep(1);
    // We do this to make sure we don't get dupe sid's
    /*
     * The following section of code will generate a unique name for a temporary
     * file and copy the uploaded file to the Media Gallery temp directory.
     * We do this to prevent any SAFE MODE issues when we later open the
     * file to determine the mime type.
     */
    if (empty($_USER['username']) || $_USER['username'] == '') {
        $_USER['username'] = '******';
    }
    $tmpPath = $_MG_CONF['tmp_path'] . '/' . $_USER['username'] . COM_makesid() . '.tmp';
    if ($upload) {
        $rc = @move_uploaded_file($filename, $tmpPath);
    } else {
        $rc = @copy($filename, $tmpPath);
        $importSource = $filename;
    }
    if ($rc != 1) {
        $errors++;
        $errMsg .= sprintf($LANG_MG02['move_error'], $filename);
        @unlink($tmpPath);
        return array(false, $errMsg);
    }
    $filename = $tmpPath;
    if ($replace > 0) {
        $new_media_id = $replace;
    } else {
        $new_media_id = COM_makesid();
    }
    $media_time = time();
    $media_upload_time = time();
    $media_user_id = $userid;
    $mimeInfo = IMG_getMediaMetaData($filename);
    $mimeExt = strtolower(substr(strrchr($file, "."), 1));
    $mimeInfo['type'] = $mimeExt;
    if (!isset($mimeInfo['mime_type']) || $mimeInfo['mime_type'] == '') {
        $mimeInfo['mime_type'] = $filetype;
    }
    $gotTN = 0;
    if (isset($mimeInfo['id3v2']['APIC'][0]['mime']) && $mimeInfo['id3v2']['APIC'][0]['mime'] == 'image/jpeg') {
        $mp3AttachdedThumbnail = $mimeInfo['id3v2']['APIC'][0]['data'];
        $gotTN = 1;
    }
    if ($mimeExt == '' || $mimeInfo['mime_type'] == 'application/octet-stream' || $mimeInfo['mime_type'] == '') {
        // assume format based on file upload info...
        switch ($filetype) {
            case 'audio/mpeg':
                $mimeInfo['type'] = 'mp3';
                $mimeInfo['mime_type'] = 'audio/mpeg';
                $mimeExt = 'mp3';
                break;
            case 'image/tga':
                $mimeInfo['type'] = 'tga';
                $mimeInfo['mime_type'] = 'image/tga';
                $mimeExt = 'tga';
                break;
            case 'image/psd':
                $mimeInfo['type'] = 'psd';
                $mimeInfo['mime_type'] = 'image/psd';
                $mimeExt = 'psd';
                break;
            case 'image/gif':
                $mimeInfo['type'] = 'gif';
                $mimeInfo['mime_type'] = 'image/gif';
                $mimeExt = 'gif';
                break;
            case 'image/jpeg':
            case 'image/jpg':
                $mimeInfo['type'] = 'jpg';
                $mimeInfo['mime_type'] = 'image/jpeg';
                $mimeExt = 'jpg';
                break;
            case 'image/png':
                $mimeInfo['type'] = 'png';
                $mimeInfo['mime_type'] = 'image/png';
                $mimeExt = 'png';
                break;
            case 'image/bmp':
                $mimeInfo['type'] = 'bmp';
                $mimeInfo['mime_type'] = 'image/bmp';
                $mimeExt = 'bmp';
                break;
            case 'application/x-shockwave-flash':
                $mimeInfo['type'] = 'swf';
                $mimeInfo['mime_type'] = 'application/x-shockwave-flash';
                $mimeExt = 'swf';
                break;
            case 'application/zip':
                $mimeInfo['type'] = 'zip';
                $mimeInfo['mime_type'] = 'application/zip';
                $mimeExt = 'zip';
                break;
            case 'audio/mpeg':
                $mimeInfo['type'] = 'mp3';
                $mimeInfo['mime_type'] = 'audio/mpeg';
                $mimeExt = 'mp3';
                break;
            case 'video/quicktime':
                $mimeInfo['type'] = 'mov';
                $mimeInfo['mime_type'] = 'video/quicktime';
                $mimeExt = 'mov';
                break;
            case 'video/x-m4v':
                $mimeInfo['type'] = 'mov';
                $mimeInfo['mime_type'] = 'video/x-m4v';
                $mimeExt = 'mov';
                break;
            case 'video/x-flv':
                $mimeInfo['type'] = 'flv';
                $mimeInfo['mime_type'] = 'video/x-flv';
                $mimeExt = 'flv';
                break;
            case 'audio/x-ms-wma':
                $mimeInfo['type'] = 'wma';
                $mimeInfo['mime_type'] = 'audio/x-ms-wma';
                $mimeExt = 'wma';
                break;
            default:
                $file_extension = strtolower(substr(strrchr($file, "."), 1));
                switch ($file_extension) {
                    case 'flv':
                        $mimeInfo['type'] = 'flv';
                        $mimeInfo['mime_type'] = 'video/x-flv';
                        $mimeExt = 'flv';
                        break;
                    case 'wma':
                        $mimeInfo['type'] = 'wma';
                        $mimeInfo['mime_type'] = 'audio/x-ms-wma';
                        $mimeExt = 'wma';
                        break;
                    default:
                        $mimeInfo['type'] = 'file';
                        if ($filetype != '') {
                            $mimeInfo['mime_type'] = $filetype;
                        } else {
                            $mimeInfo['mime_type'] = 'application/octet-stream';
                        }
                        $mimeExt = $file_extension;
                        break;
                }
        }
    }
    switch ($mimeInfo['mime_type']) {
        case 'audio/mpeg':
            $format_type = MG_MP3;
            break;
        case 'image/gif':
            $format_type = MG_GIF;
            break;
        case 'image/jpeg':
        case 'image/jpg':
            $format_type = MG_JPG;
            break;
        case 'image/png':
            $format_type = MG_PNG;
            break;
        case 'image/bmp':
            $format_type = MG_BMP;
            break;
        case 'application/x-shockwave-flash':
            $format_type = MG_SWF;
            break;
        case 'application/zip':
            $format_type = MG_ZIP;
            break;
        case 'video/mpeg':
        case 'video/x-motion-jpeg':
        case 'video/quicktime':
        case 'video/mpeg':
        case 'video/x-mpeg':
        case 'video/x-mpeq2a':
        case 'video/x-qtc':
        case 'video/x-m4v':
            $format_type = MG_MOV;
            break;
        case 'video/x-flv':
            $format_type = MG_FLV;
            break;
        case 'image/tiff':
            $format_type = MG_TIF;
            break;
        case 'image/x-targa':
        case 'image/tga':
            $format_type = MG_TGA;
            break;
        case 'image/psd':
            $format_type = MG_PSD;
            break;
        case 'application/ogg':
            $format_type = MG_OGG;
            break;
        case 'audio/x-ms-wma':
        case 'audio/x-ms-wax':
        case 'audio/x-ms-wmv':
        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':
            $format_type = MG_ASF;
            break;
        case 'application/pdf':
            $format_type = MG_OTHER;
            break;
        default:
            $format_type = MG_OTHER;
            break;
    }
    $mimeType = $mimeInfo['mime_type'];
    if ($filetype == 'video/x-m4v') {
        $mimeType = 'video/x-m4v';
        $mimeInfo['mime_type'] = 'video/x-m4v';
    }
    if (!($MG_albums[$albums]->valid_formats & $format_type)) {
        return array(false, $LANG_MG02['format_not_allowed']);
    }
    if ($replace > 0) {
        $sql = "SELECT * FROM {$_TABLES['mg_media']} WHERE media_id='" . DB_escapeString($replace) . "'";
        $result = DB_query($sql);
        $row = DB_fetchArray($result);
        $media_filename = $row['media_filename'];
    } else {
        if ($_MG_CONF['preserve_filename'] == 1) {
            $loopCounter = 0;
            $digitCounter = 1;
            $file_name = stripslashes($file);
            $file_name = MG_replace_accents($file_name);
            $file_name = preg_replace("#[ ]#", "_", $file_name);
            // change spaces to underscore
            $file_name = preg_replace('#[^\\.\\-,\\w]#', '_', $file_name);
            //only parenthesis, underscore, letters, numbers, comma, hyphen, period - others to underscore
            $file_name = preg_replace('#(_)+#', '_', $file_name);
            //eliminate duplicate underscore
            $pos = strrpos($file_name, '.');
            if ($pos === false) {
                $basefilename = $file_name;
            } else {
                $basefilename = strtolower(substr($file_name, 0, $pos));
            }
            do {
                clearstatcache();
                $media_filename = substr(md5(uniqid(rand())), 0, $digitCounter) . '_' . $basefilename;
                $loopCounter++;
                if ($loopCounter > 16) {
                    $digitCounter++;
                    $loopCounter = 0;
                }
            } while (MG_file_exists($media_filename));
        } else {
            do {
                clearstatcache();
                $media_filename = md5(uniqid(rand()));
            } while (MG_file_exists($media_filename));
        }
    }
    // replace a few mime extentions here...
    //
    $mimeExtLower = strtolower($mimeExt);
    if ($mimeExtLower == 'php') {
        $mimeExt = 'phps';
    } else {
        if ($mimeExtLower == 'pl') {
            $mimeExt = 'txt';
        } else {
            if ($mimeExtLower == 'cgi') {
                $mimeExt = 'txt';
            } else {
                if ($mimeExtLower == 'py') {
                    $mimeExt = 'txt';
                } else {
                    if ($mimeExtLower == 'sh') {
                        $mimeExt = 'txt';
                    } else {
                        if ($mimeExtLower == 'rb') {
                            $mimeExt = 'txt';
                        }
                    }
                }
            }
        }
    }
    $disp_media_filename = $media_filename . '.' . $mimeExt;
    switch ($mimeType) {
        case 'image/psd':
        case 'image/x-targa':
        case 'image/tga':
        case 'image/photoshop':
        case 'image/x-photoshop':
        case 'image/psd':
        case 'application/photoshop':
        case 'application/psd':
        case 'image/tiff':
        case 'image/gif':
        case 'image/jpeg':
        case 'image/jpg':
        case 'image/png':
        case 'image/bmp':
            if ($mimeType == 'image/psd' || $mimeType == 'image/x-targa' || $mimeType == 'image/tga' || $mimeType == 'image/photoshop' || $mimeType == 'image/x-photoshop' || $mimeType == 'image/psd' || $mimeType == 'application/photoshop' || $mimeType == 'application/psd' || $mimeType == 'image/tiff') {
                $media_orig = $_MG_CONF['path_mediaobjects'] . 'orig/' . $media_filename[0] . '/' . $media_filename . "." . $mimeExt;
                $media_disp = $_MG_CONF['path_mediaobjects'] . 'disp/' . $media_filename[0] . '/' . $media_filename . ".jpg";
                $media_tn = $_MG_CONF['path_mediaobjects'] . 'tn/' . $media_filename[0] . '/' . $media_filename . ".jpg";
            } else {
                $media_orig = $_MG_CONF['path_mediaobjects'] . 'orig/' . $media_filename[0] . '/' . $media_filename . "." . $mimeExt;
                $media_disp = $_MG_CONF['path_mediaobjects'] . 'disp/' . $media_filename[0] . '/' . $media_filename . "." . $mimeExt;
                $media_tn = $_MG_CONF['path_mediaobjects'] . 'tn/' . $media_filename[0] . '/' . $media_filename . "." . $mimeExt;
            }
            $mimeType = $mimeInfo['mime_type'];
            // process image file
            $media_time = getOriginationTimestamp($filename);
            if ($media_time == null || $media_time < 0) {
                $media_time = time();
            }
            $rc = @copy($filename, $media_orig);
            if ($rc != 1) {
                $errors++;
                $errMsg .= sprintf($LANG_MG02['move_error'], $filename);
            } else {
                if ($purgefiles) {
                    @unlink($importSource);
                }
                @chmod($media_orig, 0644);
                list($rc, $msg) = MG_convertImage($media_orig, $media_tn, $media_disp, $mimeExt, $mimeType, $albums, $media_filename, $dnc);
                if ($rc == false) {
                    $errors++;
                    $errMsg .= $msg;
                    // sprintf($LANG_MG02['convert_error'],$filename);
                } else {
                    $mediaType = 0;
                    if ($_MG_CONF['discard_original'] == 1 && ($mimeType == 'image/jpeg' || $mimeType == 'image/jpg' || $mimeType == 'image/png' || $mimeType == 'image/bmp' || $mimeType == 'image/gif')) {
                        if ($_MG_CONF['jhead_enabled'] && ($mimeType == 'image/jpeg' || $mimeType == 'image/jpg')) {
                            $rc = MG_execWrapper('"' . $_MG_CONF['jhead_path'] . "/jhead" . '"' . " -te " . $media_orig . " " . $media_disp);
                        }
                        @unlink($media_orig);
                    }
                    if ($MG_albums[$albums]->wm_auto) {
                        if ($_MG_CONF['discard_original'] == 1) {
                            $rc = MG_watermark($media_disp, $albums, 1);
                            if ($rc == TRUE) {
                                $successfulWatermark = 1;
                            }
                        } else {
                            $rc1 = MG_watermark($media_orig, $albums, 1);
                            $rc2 = MG_watermark($media_disp, $albums, 0);
                            if ($rc1 == TRUE && $rc2 == TRUE) {
                                $successfulWatermark = 1;
                            }
                        }
                    }
                    if ($dnc != 1) {
                        if ($mimeType != 'image/tga' && $mimeType != 'image/x-targa' && $mimeType != 'image/tiff') {
                            if ($mimeType != 'image/photoshop' && $mimeType != 'image/x-photoshop' && $mimeType != 'image/psd' && $mimeType != 'application/photoshop' && $mimeType != 'application/psd') {
                                $mimeExt = 'jpg';
                                $mimeType = 'image/jpeg';
                            }
                        }
                    }
                }
            }
            break;
        case 'video/quicktime':
        case 'video/mpeg':
        case 'video/x-flv':
        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-shockwave-flash':
        case 'video/mp4':
        case 'video/x-m4v':
            $mimeType = $mimeInfo['mime_type'];
            if ($filetype == 'video/mp4') {
                $mimeExt = 'mp4';
            }
            // process video format
            $media_orig = $_MG_CONF['path_mediaobjects'] . 'orig/' . $media_filename[0] . '/' . $media_filename . '.' . $mimeExt;
            $rc = @copy($filename, $media_orig);
            if ($rc != 1) {
                $errors++;
                $errMsg .= sprintf($LANG_MG02['move_error'], $filename);
            } else {
                if ($purgefiles) {
                    @unlink($importSource);
                }
                @chmod($media_orig, 0644);
                $mediaType = 1;
            }
            $video_attached_thumbnail = MG_videoThumbnail($albums, $media_orig, $media_filename);
            break;
        case 'application/ogg':
        case 'audio/mpeg':
        case 'audio/x-ms-wma':
        case 'audio/x-ms-wax':
        case 'audio/x-ms-wmv':
            $mimeType = $mimeInfo['mime_type'];
            // process audio format
            $media_orig = $_MG_CONF['path_mediaobjects'] . 'orig/' . $media_filename[0] . '/' . $media_filename . '.' . $mimeExt;
            $rc = @copy($filename, $media_orig);
            if (isset($mimeInfo['tags']['id3v1']['title'][0])) {
                if ($caption == '') {
                    $caption = $mimeInfo['tags']['id3v1']['title'][0];
                }
            }
            if (isset($mimeInfo['tags']['id3v1']['artist'][0])) {
                $artist = DB_escapeString($mimeInfo['tags']['id3v1']['artist'][0]);
            }
            if (isset($mimeInfo['tags']['id3v2']['genre'][0])) {
                $genre = DB_escapeString($mimeInfo['tags']['id3v2']['genre'][0]);
            }
            if (isset($mimeInfo['tags']['id3v1']['album'][0])) {
                $musicAlbum = DB_escapeString($mimeInfo['tags']['id3v1']['album'][0]);
            }
            if ($rc != 1) {
                $errors++;
                $errMsg .= sprintf($LANG_MG02['move_error'], $filename);
            } else {
                if ($purgefiles) {
                    @unlink($importSource);
                }
                $mediaType = 2;
            }
            break;
        case 'zip':
        case 'application/zip':
            if ($_MG_CONF['zip_enabled']) {
                $errMsg .= MG_processZip($filename, $albums, $purgefiles, $media_filename);
                break;
            }
            // NO BREAK HERE, fall through if enable zip isn't allowed
        // NO BREAK HERE, fall through if enable zip isn't allowed
        default:
            $media_orig = $_MG_CONF['path_mediaobjects'] . 'orig/' . $media_filename[0] . '/' . $media_filename . "." . $mimeExt;
            $mimeType = $mimeInfo['mime_type'];
            $rc = @copy($filename, $media_orig);
            if ($rc != 1) {
                $errors++;
                $errMsg .= sprintf($LANG_MG02['move_error'], $filename);
            } else {
                if ($purgefiles) {
                    @unlink($importSource);
                }
                $mediaType = 4;
            }
            $mediaType = 4;
            break;
    }
    // update quota
    $quota = $MG_albums[$albums]->album_disk_usage;
    if ($_MG_CONF['discard_original'] == 1) {
        $quota += @filesize($_MG_CONF['path_mediaobjects'] . 'orig/' . $media_filename[0] . '/' . $media_filename . '.' . $mimeExt);
        $quota += @filesize($_MG_CONF['path_mediaobjects'] . 'disp/' . $media_filename[0] . '/' . $media_filename . '.jpg');
    } else {
        $quota += @filesize($_MG_CONF['path_mediaobjects'] . 'orig/' . $media_filename[0] . '/' . $media_filename . '.' . $mimeExt);
    }
    DB_query("UPDATE {$_TABLES['mg_albums']} SET album_disk_usage=" . $quota . " WHERE album_id=" . $albums);
    if ($errors) {
        @unlink($tmpPath);
        return array(false, $errMsg);
    }
    if (($mimeType != 'application/zip' || $_MG_CONF['zip_enabled'] == 0) && $errors == 0) {
        // Now we need to process an uploaded thumbnail
        if ($gotTN == 1) {
            $mp3TNFilename = $_MG_CONF['tmp_path'] . '/mp3tn' . time() . '.jpg';
            $fn = fopen($mp3TNFilename, "w");
            fwrite($fn, $mp3AttachdedThumbnail);
            fclose($fn);
            $saveThumbnailName = $_MG_CONF['path_mediaobjects'] . 'tn/' . $media_filename[0] . '/tn_' . $media_filename;
            MG_attachThumbnail($albums, $mp3TNFilename, $saveThumbnailName);
            @unlink($mp3TNFilename);
            $atttn = 1;
        } else {
            if ($atttn == 1) {
                $saveThumbnailName = $_MG_CONF['path_mediaobjects'] . 'tn/' . $media_filename[0] . '/tn_' . $media_filename;
                MG_attachThumbnail($albums, $thumbnail, $saveThumbnailName);
            }
        }
        if ($video_attached_thumbnail) {
            $atttn = 1;
        }
        if ($MG_albums[$albums]->enable_html != 1) {
            //        if ($_MG_CONF['htmlallowed'] != 1 ) {
            $media_desc = DB_escapeString(htmlspecialchars(strip_tags(COM_checkWords(COM_killJS($description)))));
            $media_caption = DB_escapeString(htmlspecialchars(strip_tags(COM_checkWords(COM_killJS($caption)))));
            $media_keywords = DB_escapeString(htmlspecialchars(strip_tags(COM_checkWords(COM_killJS($keywords)))));
        } else {
            $media_desc = DB_escapeString(COM_checkHTML(COM_killJS($description)));
            $media_caption = DB_escapeString(COM_checkHTML(COM_killJS($caption)));
            $media_keywords = DB_escapeString(COM_checkHTML(COM_killJS($keywords)));
        }
        // Check and see if moderation is on.  If yes, place in mediasubmission
        if ($MG_albums[$albums]->moderate == 1 && !$MG_albums[0]->owner_id) {
            $tableMedia = $_TABLES['mg_mediaqueue'];
            $tableMediaAlbum = $_TABLES['mg_media_album_queue'];
            $queue = 1;
        } else {
            $tableMedia = $_TABLES['mg_media'];
            $tableMediaAlbum = $_TABLES['mg_media_albums'];
            $queue = 0;
        }
        $original_filename = DB_escapeString($file);
        if ($MG_albums[$albums]->filename_title) {
            if ($media_caption == '') {
                $pos = strrpos($original_filename, '.');
                if ($pos === false) {
                    $media_caption = $original_filename;
                } else {
                    $media_caption = substr($original_filename, 0, $pos);
                }
            }
        }
        $resolution_x = 0;
        $resolution_y = 0;
        // try to find a resolution if video...
        if ($mediaType == 1) {
            switch ($mimeType) {
                case 'application/x-shockwave-flash':
                case 'video/quicktime':
                case 'video/mpeg':
                case 'video/x-m4v':
                    if (isset($mimeInfo['video']['resolution_x']) && isset($mimeInfo['video']['resolution_x'])) {
                        $resolution_x = $mimeInfo['video']['resolution_x'];
                        $resolution_y = $mimeInfo['video']['resolution_y'];
                    } else {
                        $resolution_x = -1;
                        $resolution_y = -1;
                    }
                    break;
                case 'video/x-flv':
                    if ($mimeInfo['video']['resolution_x'] < 1 || $mimeInfo['video']['resolution_y'] < 1) {
                        if (isset($mimeInfo['meta']['onMetaData']['width']) && isset($mimeInfo['meta']['onMetaData']['height'])) {
                            $resolution_x = $mimeInfo['meta']['onMetaData']['width'];
                            $resolution_y = $mimeInfo['meta']['onMetaData']['height'];
                        } else {
                            $resolution_x = -1;
                            $resolution_y = -1;
                        }
                    } else {
                        $resolution_x = $mimeInfo['video']['resolution_x'];
                        $resolution_y = $mimeInfo['video']['resolution_y'];
                    }
                    break;
                case 'video/x-ms-asf':
                case 'video/x-ms-asf-plugin':
                case 'video/avi':
                case 'video/msvideo':
                case 'video/x-msvideo':
                case 'video/avs-video':
                case 'video/x-ms-wmv':
                case 'video/x-ms-wvx':
                case 'video/x-ms-wm':
                case 'application/x-troff-msvideo':
                    if (isset($mimeInfo['video']['streams']['2']['resolution_x']) && isset($mimeInfo['video']['streams']['2']['resolution_y'])) {
                        $resolution_x = $mimeInfo['video']['streams']['2']['resolution_x'];
                        $resolution_y = $mimeInfo['video']['streams']['2']['resolution_y'];
                    } else {
                        $resolution_x = -1;
                        $resolution_y = -1;
                    }
                    break;
            }
        }
        if ($replace > 0) {
            $sql = "UPDATE " . $tableMedia . " SET\n\t        \t\t\t\t\tmedia_filename='" . DB_escapeString($media_filename) . "',\n\t        \t\t\t\t\tmedia_original_filename='{$original_filename}',\n\t        \t\t\t\t\tmedia_mime_ext='" . DB_escapeString($mimeExt) . "',\n\t        \t\t\t\t\tmime_type='" . DB_escapeString($mimeType) . "',\n\t        \t\t\t\t\tmedia_time='" . DB_escapeString($media_time) . "',\n\t        \t\t\t\t\tmedia_user_id='" . DB_escapeString($media_user_id) . "',\n\t        \t\t\t\t\tmedia_type='" . DB_escapeString($mediaType) . "',\n\t        \t\t\t\t\tmedia_upload_time='" . DB_escapeString($media_upload_time) . "',\n\t        \t\t\t\t\tmedia_watermarked='" . DB_escapeString($successfulWatermark) . "',\n\t        \t\t\t\t\tmedia_resolution_x='" . DB_escapeString($resolution_x) . "',\n\t        \t\t\t\t\tmedia_resolution_y='" . DB_escapeString($resolution_y) . "'\n\t        \t\t\t\t\tWHERE media_id='" . DB_escapeString($replace) . "'";
            DB_query($sql);
        } else {
            $sql = "INSERT INTO " . $tableMedia . " (media_id,media_filename,media_original_filename,media_mime_ext,media_exif,mime_type,media_title,media_desc,media_keywords,media_time,media_views,media_comments,media_votes,media_rating,media_tn_attached,media_tn_image,include_ss,media_user_id,media_user_ip,media_approval,media_type,media_upload_time,media_category,media_watermarked,v100,maint,media_resolution_x,media_resolution_y,remote_media,remote_url,artist,album,genre)\n\t                VALUES ('{$new_media_id}','{$media_filename}','{$original_filename}','{$mimeExt}','1','{$mimeType}','{$media_caption}','{$media_desc}','{$media_keywords}','{$media_time}','0','0','0','0.00','{$atttn}','','1','{$media_user_id}','','0','{$mediaType}','{$media_upload_time}','{$category}','{$successfulWatermark}','0','0',{$resolution_x},{$resolution_y},0,'','{$artist}','{$musicAlbum}','{$genre}');";
            DB_query($sql);
            $x = 0;
            $sql = "SELECT MAX(media_order) + 10 AS media_seq FROM " . $_TABLES['mg_media_albums'] . " WHERE album_id = " . $albums;
            $result = DB_query($sql);
            $row = DB_fetchArray($result);
            $media_seq = $row['media_seq'];
            if ($media_seq < 10) {
                $media_seq = 10;
            }
            $sql = "INSERT INTO " . $tableMediaAlbum . " (media_id, album_id, media_order) VALUES ('{$new_media_id}', {$albums}, {$media_seq} )";
            DB_query($sql);
            if ($mediaType == 1 && $resolution_x > 0 && $resolution_y > 0 && $_MG_CONF['use_default_resolution'] == 0) {
                DB_save($_TABLES['mg_playback_options'], 'media_id,option_name,option_value', "'{$new_media_id}','width',       '{$resolution_x}'");
                DB_save($_TABLES['mg_playback_options'], 'media_id,option_name,option_value', "'{$new_media_id}','height',      '{$resolution_y}'");
            }
            // update the media count for the album, only if no moderation...
            if ($queue == 0) {
                $MG_albums[$albums]->media_count++;
                DB_query("UPDATE " . $_TABLES['mg_albums'] . " SET media_count=" . $MG_albums[$albums]->media_count . ",last_update=" . $media_upload_time . " WHERE album_id='" . $MG_albums[$albums]->id . "'");
                if ($_MG_CONF['update_parent_lastupdated'] == 1) {
                    $currentAID = $MG_albums[$albums]->parent;
                    while ($MG_albums[$currentAID]->id != 0) {
                        DB_query("UPDATE " . $_TABLES['mg_albums'] . " SET last_update=" . $media_upload_time . " WHERE album_id='" . $MG_albums[$currentAID]->id . "'");
                        $currentAID = $MG_albums[$currentAID]->parent;
                    }
                }
                if ($MG_albums[$albums]->cover == -1 && ($mediaType == 0 || $atttn == 1)) {
                    if ($atttn == 1) {
                        $covername = 'tn_' . $media_filename;
                    } else {
                        $covername = $media_filename;
                    }
                    DB_query("UPDATE {$_TABLES['mg_albums']} SET album_cover_filename='" . $covername . "'" . " WHERE album_id='" . $MG_albums[$albums]->id . "'");
                }
            }
            $x++;
        }
    }
    if ($queue) {
        $errMsg .= $LANG_MG01['successful_upload_queue'];
        // ' successfully placed in Moderation queue';
    } else {
        $errMsg .= $LANG_MG01['successful_upload'];
        // ' successfully uploaded to album';
    }
    if ($queue == 0) {
        require_once $_CONF['path'] . 'plugins/mediagallery/include/rssfeed.php';
        MG_buildFullRSS();
        MG_buildAlbumRSS($albums);
        CACHE_remove_instance('whatsnew');
    }
    @unlink($tmpPath);
    return array(true, $errMsg);
}
コード例 #6
0
ファイル: upload.class.php プロジェクト: NewRoute/glfusion
 /**
  * Uploads any posted files.
  *
  * @return   boolean returns true if no errors were encountered otherwise false
  */
 function uploadFiles()
 {
     // Before we do anything, let's see if we are limiting file uploads by
     // IP address and, if so, verify the poster is originating from one of
     // those places
     if ($this->_limitByIP) {
         if (!in_array($_SERVER['REMOTE_ADDR'], $this->_allowedIPS)) {
             $this->_addError('The IP, ' . $_SERVER['REMOTE_ADDR'] . ' is not in the list of ' . 'accepted IP addresses.  Refusing to allow file upload(s)');
             return false;
         }
     }
     if (empty($this->_filesToUpload)) {
         if (empty($this->_fieldName) || $this->_fieldName == '') {
             $this->_filesToUpload = $_FILES;
         } else {
             $this->_filesToUpload = $_FILES[$this->_fieldName];
         }
     }
     $numFiles = $this->numFiles();
     // For security sake, check to make sure a DOS isn't happening by making
     // sure there is a limit of the number of files being uploaded
     if ($numFiles > $this->_maxFileUploadsPerForm) {
         $this->_addError('Max. number of files you can upload from a form is ' . $this->_maxFileUploadsPerForm . ' and you sent ' . $numFiles);
         return false;
     }
     // Verify upload directory is valid
     if (!$this->_fileUploadDirectory) {
         $this->_addError('No Upload Directory Specified, use setPath() method');
     }
     // Verify allowed mime types exist
     if (!$this->_allowedMimeTypes && $this->_allowAnyType == false) {
         $this->_addError('No allowed mime types specified, use setAllowedMimeTypes() method');
     }
     if (is_array($this->_filesToUpload['name'])) {
         foreach ($this->_filesToUpload["error"] as $key => $error) {
             if ($error == UPLOAD_ERR_OK) {
                 $this->_currentFile['name'] = $this->_filesToUpload["name"][$key];
                 $this->_currentFile['tmp_name'] = $this->_filesToUpload["tmp_name"][$key];
                 $this->_currentFile['type'] = $this->_filesToUpload["type"][$key];
                 $this->_currentFile['size'] = $this->_filesToUpload["size"][$key];
                 $this->_currentFile['error'] = $this->_filesToUpload["error"][$key];
                 $this->_currentFile['_data_dir'] = isset($this->_filesToUpload["_data_dir"][$key]) ? $this->_filesToUpload["_data_dir"][$key] : '';
                 $this->_currentFile['localerror'] = array();
                 $metaData = IMG_getMediaMetaData($this->_currentFile['tmp_name']);
                 if ($metaData['mime_type'] != '') {
                     $this->_currentFile['type'] = $metaData['mime_type'];
                 } else {
                     $this->_currentFile['type'] = 'application/octet-stream';
                 }
                 if (!empty($this->_currentFile['name'])) {
                     // Verify file meets size limitations
                     if (!$this->_fileSizeOk()) {
                         $this->_addError('File, ' . $this->_currentFile['name'] . ', is bigger than the ' . $this->_maxFileSize . ' byte limit');
                         $this->_currentFile['localerror'][] = $this->_currentFile['name'] . ', is bigger than the ' . $this->_maxFileSize . ' byte limit';
                     }
                     // If all systems check, do the upload
                     if ($this->checkMimeType() and $this->_imageSizeOK() and empty($this->_currentFile['localerror'])) {
                         if ($this->_copyFile()) {
                             $this->_uploadedFiles[] = $this->_fileUploadDirectory . '/' . $this->_getDestinationName();
                         }
                     }
                     $this->_currentFile = array();
                     if ($this->areErrors() and !$this->_continueOnError) {
                         return false;
                     }
                 }
             } else {
                 if ($error != UPLOAD_ERR_NO_FILE) {
                     $this->_uploadError($error);
                 }
             }
             $this->_imageIndex++;
         }
     } else {
         if ($this->_filesToUpload['name'] != '' && $this->_filesToUpload['error'] == UPLOAD_ERR_OK) {
             $this->_currentFile['name'] = $this->_filesToUpload["name"];
             $this->_currentFile['tmp_name'] = $this->_filesToUpload["tmp_name"];
             $this->_currentFile['type'] = $this->_filesToUpload["type"];
             $this->_currentFile['size'] = $this->_filesToUpload["size"];
             $this->_currentFile['error'] = $this->_filesToUpload["error"];
             $this->_currentFile['_data_dir'] = isset($this->_filesToUpload["_data_dir"]) ? $this->_filesToUpload["_data_dir"] : '';
             $metaData = IMG_getMediaMetaData($this->_currentFile['tmp_name']);
             if (isset($metaData['mime_type']) && $metaData['mime_type'] != '') {
                 $this->_currentFile['type'] = $metaData['mime_type'];
             } else {
                 $this->_currentFile['type'] = 'application/octet-stream';
             }
             if (!empty($this->_currentFile['name'])) {
                 // Verify file meets size limitations
                 if (!$this->_fileSizeOk()) {
                     $this->_addError('File, ' . $this->_currentFile['name'] . ', is bigger than the ' . $this->_maxFileSize . ' byte limit');
                 }
                 // If all systems check, do the upload
                 if ($this->checkMimeType() and $this->_imageSizeOK() and !$this->areErrors()) {
                     if ($this->_copyFile()) {
                         $this->_uploadedFiles[] = $this->_fileUploadDirectory . '/' . $this->_getDestinationName();
                     }
                 }
                 if ($this->areErrors() and !$this->_continueOnError) {
                     return false;
                 }
             }
         } else {
             $this->_uploadError($this->_filesToUpload['error']);
         }
     }
     // This function returns false if any errors were encountered
     if ($this->areErrors()) {
         return false;
     } else {
         return true;
     }
 }
コード例 #7
0
ファイル: lib-upload.php プロジェクト: NewRoute/glfusion
function MG_attachThumbnail($aid, $thumbnail, $mediaFilename)
{
    global $_CONF, $_MG_CONF, $MG_albums;
    $makeSquare = 0;
    if ($_MG_CONF['verbose']) {
        COM_errorLog("MG Upload: Processing attached thumbnail: " . $thumbnail);
    }
    if ($MG_albums[$aid]->tn_size == 3 || $MG_albums[$aid]->tn_size == 4) {
        $tnHeight = $MG_albums[$aid]->tnHeight;
        $tnWidth = $MG_albums[$aid]->tnWidth;
        if ($MG_albums[$aid]->tn_size == 4) {
            $makeSquare = 1;
        }
    } else {
        if ($_MG_CONF['thumbnail_actual_size'] == 1) {
            switch ($MG_albums[$aid]->tn_size) {
                case 0:
                    $tnHeight = 100;
                    $tnWidth = 100;
                    break;
                case 1:
                    $tnHeight = 150;
                    $tnWidth = 150;
                    break;
                default:
                    $tnHeight = 200;
                    $tnWidth = 200;
                    break;
            }
        } else {
            $tnHeight = 200;
            $tnWidth = 200;
        }
    }
    $tn_mime_type = IMG_getMediaMetaData($thumbnail);
    if (!isset($tn_mime_type['mime_type'])) {
        $tn_mime_type['mime_type'] = '';
    }
    switch ($tn_mime_type['mime_type']) {
        case 'image/gif':
            $tnExt = '.gif';
            break;
        case 'image/jpeg':
        case 'image/jpg':
            $tnExt = '.jpg';
            break;
        case 'image/png':
            $tnExt = '.png';
            break;
        case 'image/bmp':
            $tnExt = '.bmp';
            break;
        default:
            COM_errorLog("MG_attachThumbnail: Invalid graphics type for attached thumbnail.");
            return false;
    }
    $attach_tn = $mediaFilename . $tnExt;
    if ($makeSquare) {
        list($rc, $msg) = IMG_squareThumbnail($thumbnail, $attach_tn, $tnWidth, $tn_mime_type['mime_type'], 1);
    } else {
        list($rc, $msg) = IMG_resizeImage($thumbnail, $attach_tn, $tnHeight, $tnWidth, $tn_mime_type['mime_type'], 1);
    }
    return true;
}
コード例 #8
0
ファイル: lib-media.php プロジェクト: NewRoute/glfusion
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);
}