When creating custom content types to the Telligent Community platform and utilizing the platform editor within the UI managing that content (using the $core_v2_editor widget API), the editor will allow drag-and-drop and menu-based file uploading into the HTML content if that content supports embedded files.
[toc]
Why Would I Want to Enable Embedded Files?
Embedded files are useful when authoring rich formatted content (HTML) to allow inclusion of images, videos, documents, and other media and files to provide more flexibility and interactivity.
Implementing Support for Embedded Files
To add support for embedded files within a custom content type, the IFileEmbeddableContentType plugin type should also be implemented on your content type (which requires a reference to Telligent.Evolution.Core.dll). The IFileEmbeddableContentType
interface extends IContentType to add members that enable the content type to interact with the Telligent Community platform regarding embedded files.
Because an implementation of IFileEmbeddableContentType
is dependent on a custom content type which is out-of-scope for this topic, I'll show examples from private messaging in the core platform.
We'll implement the IFileEmbeddedContentType
, which requires two members to be implemented. First, CanAddFiles()
identifies whether a user can add files to this content type:
public bool CanAddFiles(int userId) { var user = Users.GetUser(userId); if (user == null || user.IsAnonymous) return false; return true; }
For private messaging, any non-anonymous user can embed files. For other applications, the ability to embed files may be dependent on the application or container/group the content is being created within. To detect the context of the request, the current page's context can be retrieved by analyzing Url.CurrentContext or using another mechanism for detecting the context of the CanAddFiles()
request.
When CanAddFiles()
returns true
, file embedding functionality within the platform content editor will be enabled, otherwise, these functions will not be available.
The only remaining requirement for an IFileEmbeddableContentType
implementation is the SetController()
method:
private IFileEmbeddableContentTypeController _embeddedFileController; public void SetController(IFileEmbeddableContentTypeController controller) { _embeddedFileController = controller; }
This method provides the plugin with a controller enabling the extraction and reassignment of embedded files within HTML content.
When files are uploaded through the editor, they're placed in a temporary file store within the Centralized File System. Files placed in this temporary location are only accessible to the user who uploaded them and are automatically deleted after 2 hours (by default) of inactivity. Content supporting embedded files should move this temporary content to a final storage location suitably secured for the content type. To implement the movement of files to a final storage location, events related to the creation or editing of content should be handled and the IFileEmbeddableContentTypeController provided to the plugin through the SetController()
method should be used.