Ticket #1572 (new enhancement)

Opened 13 months ago

Last modified 2 months ago

Better handling of different media types

Reported by: sminnee Owned by: ischommer
Priority: medium Milestone:
Component: CMS - Files and Images section Version:
Severity: medium effort / impact Keywords:
Cc: Hours:

Description

There isn't much support for dealing with media other than images. There are two things that would be nice to do better:

  • When including a download link, show a little widget indicate file type and file size.
  • When inserting a video, display it inline

There are two places where these could be used:

  • When you are editing content, let people insert these representations of files into the content.
  • When referencing a File object programatically or in a template, be able to get this representation and insert it into the code.

One way of achieving this is to have an Inline() function on the File object, that would return the HTML to be inserted for representing this object Inline.

But, how do you decide what the Inline() function returns? There are a few factors that will be relevant here:

  • The system needs to be extensible, so that 3rd party developers can come up with alternative representations for files, for example, a new video-inlining mechanism.
  • The most basic decision-making factor would be the file extension. We could do more fancy stuff if we were able to have more complex decision-making factors, but file extension would be acceptable as a minimum.
  • We would need to support a default handler.

If we were to stick to solely choosing a handler based on file extension - and I think this is a good move - we could

  • Create a base class, FileFormatter?, that had an abstract function static format_inline(File $file)
  • Create a static function File::register_formatter($extensionList, $formatterClass, $priority), that would be responsible for registering the formatters that could be used. $priority would give us a way of deciding which formatter should be used - letting a module or project-specific code override the formatters defined by default.

The File class would maintain a static array of $registered_formatters, that it would use to identify which formatterClass to use, and then call a function such as this to return it:

function Inline() {
  $formatterClass = self::$registered_formatters[$this->Extension]['className'];
  return eval("return {$formatterClass}::format_inline($this);");
}

If people wanted to define formatters that used more sophisticated criteria than file extension, they could do so in their format_inline() function.

Once we have such a system set up, template authors can put $MyFileField?.Inline in their templates. To get the inlining working in the WYSIWYG editor, we would need to set up some kind of interface with an AJAX call to FileObj?.Inline().

Change History

Changed 13 months ago by smagnusson

From a content editor's perspective I certainly want to be able to insert PDF and movie files into my WYSIWYG editor. I have some easy ways to get this moving forward. If you see a need for the in-template stuff, then cool, this may just be useful to a developer and thus not on my radar :))

So with PDFs (and doc, xls, etc) we could simply use CSS to embellish text links with icons. This means your HTML is no different (nice) but the presentation looks slick. This is rarely-used, innovative stuff, in my opinion. See my AnEventApart? Day2 write up at http://www.silverstripe.com/aneventapart-san-francisco-day-two/ which showed this Eric Meyer code:

a[href$=".pdf"] {

padding-right: 18px; background: url(/pix/pdf-icon.gif) 100% 50% no-repeat;

}

With movies, I certainly suggest them working like the youtube-in-blog type things. That's what I've wanted for a long time at SilverStripe?.com, and in fact Lakshaan from GSOC was going to make a 'add youtube video' button in the editor, because it was very similar to 'add flash file' into the editor.

To expand his idea, I think having an 'insert movie' button which asks for either; 1. choose file from /assets/ folder (which is then embedded into a flash file to play it)

2. provide http:// URL for a video (I've not thought of ramifications of this but it seems ok?)

3. provide a youtube embed string. Perhaps this can be an extension of "2". You simply need SilverStripe? to understand what to do if you type in

a) a youtube id (EQ2vLdFTaT0) b) a youtube URL (http://www.youtube.com/watch?v=EQ2vLdFTaT0) c) a youtube embed string (<object width="425" height="355"><param name="movie" value="http://www.youtube.com/v/EQ2vLdFTaT0&rel=1"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/EQ2vLdFTaT0&rel=1" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></embed></object>)

Changed 13 months ago by lancer

Could be interesting:

http://cvs.horde.org/framework/MIME/

Changed 13 months ago by ischommer

having Inline() is definetly better than relying on subclasses, and making it extensible by 3rd parties - all the better!

one small note:

So with PDFs (and doc, xls, etc) we could simply use CSS to embellish text links with icons.

regexing attributes through CSS is not a widely supported technique (yet). as we have control over generating the content anyway, i would resort to special classnames instead (e.g. "filetype-pdf", "filetype-xls", ...).

Changed 13 months ago by sminnee

  • milestone set to 2.2.1

Scheduling this for 2.2.1.

Changed 13 months ago by sminnee

Once this is done, we should look at how we can use similar techniques for managing captions on images in #1805.

Changed 11 months ago by sminnee

  • milestone changed from 2.2.2 feature-lock to 2.3

Changed 10 months ago by sminnee

  • type changed from defect to enhancement

Changed 2 months ago by sminnee

  • milestone 2.3.0 deleted
Note: See TracTickets for help on using tickets.