Products and Services
Graffiti CMS
Learn more about our simple content publishing platform.
Harvest Reporting Server
Get business intelligence tools for measuring online behavior.
Professional Services
Consulting, creative, and Web services from the people who know Community Server best.
Solutions
Telligent
Learn more about our team at Telligent.com.
 

Implementing Custom File Viewers

File viewers are .net classes that implement the CommunityServer.Components.IFileViewer interface and support viewing and resizing images, viewing uploaded and remote video files, viewing video from online video services, and playing uploaded and remote audio clips.

 

This interface defines only two methods (with two variations each): Render and GetMediaType.

Render

The Render method renders a provided file or URL.

string Render(ICentralizedFile file, FileViewType viewType, int width, int height)

string Render(Uri url, FileViewType viewType, int width, int height)

The Render method gets the HTML markup used to render a file or URL configured for viewing by this file viewer. For local files, an ICentralizedFile-implementing object is provided that represents a file in the Centralized File System. For URLs, the Uri object representing the URL is provided. For both local files and URLs, the type of view (Preview or View) and the requested width and height (in pixels) are provided.

GetMediaType

The GetMediaType retrieves the type of content that will be generated when a file or URL is rendered.

PostMediaType GetMediaType(ICentralizedFile file, FileViewType viewType)

PostMediaType GetMediaType(Uri url, FileViewType viewType)

The GetMediaType method determines what type of media will be rendered for a given view of a file. The returned value is from the PostMediaType enumeration (Empty, Image, Video, Audio, Poll). This value is used to set a post’s PostMedia property based on the files referenced within the post and/or the post attachment. It can also be used to perform conditional formatting via the post-attachment-related view condition controls in Chameleon.

Implementation Guidelines

Width and Height are Suggestions

You should treat the width and height provided to the IFileViewer.Render method as suggestions and/or not-to-exceed values. For example, rending an audio clip at 400 pixels in height probably will not make sense. Instead, as long as the audio clip fits within the suggested height, it could render at 32 pixels in height, which is a more reasonable value.

View and Preview Rendering

When the FileViewType.Preview is requested, a static and or quick-rendering version of the file should be displayed, generally an image or icon. When the FileViewType.View is requested, the full and/or interactive version of the file can be rendered, such as a video player or audio player:

<object />, <embed />

File vs URL Support

File viewers do not need to support both File and URL-based files. The YouTubeFileViewer, for example, supports only URLs from YouTube.

If a file viewer does not support local files,you can omit the extensions attribute on its <add /> node in the <FileViewers /> region of the communityserver.config file and the Render and GetMediaType methods that accept ICentralizedFile objects can throw exceptions or return default values (since they should never be called).

If a file viewer does not support URLs, you can omit the urlPattern on its <add /> node in the <FileViewers /> region of the communityserver.config file and the Render and GetMediaType methods that accept Uri objects can throw exceptions or return default values (since they should never be called).

FileViewer Priority

Order does matter within the <FileViewers /> region of the communityserver.config file. For duplicate extensions (where multiple file viewers handle the same extension), the last viewer registered to handle the extension is used to handle all files with the extension.

For overlapping urlPatterns (where a single URL may match the urlPattern of more than on file viewer), the first matching file viewer is used to handle the URL.

You can register the same file viewer multiple times (with different extensions or urlPatterns ) in the <FileViewers /> list to implement the desired priority.

Rendering JavaScript

In general, the IFileViewer.Render method can render whatever markup it chooses. When rendering JavaScript, however, Telligent suggests you use the following guidelines:

  • Render Scripts Inline 

When including script resources, either inline or external, render the <script></script> tag within the string returned by the Render method instead of attempting to register the script via the Page object or CSControlUtility class. This will ensure that media embedding and the out-of-the-box slide shows will function properly.

  • Do Not Use document.write

In general, you should not use document.write in JavaScript. To support media embedding, out-of-the-box slide shows, and XHTML in general, file viewers should not use document.write.

Related Topics