コード例 #1
0
 /**
  * Add MIME types and/or file extensions and associated callbacks to the 
  * list.
  * 
  * This allows plugins to override/define ways of displaying specific files. 
  * The most obvious example of where this would come in handy is to define 
  * ways of displaying uncommon files, such as QTVR, or novel ways of 
  * displaying more common files, such as using iPaper to display PDFs.
  *
  * @see add_mime_display_type()
  * @internal This method (and the properties upon which it operates) are 
  * static because it gets called prior to instantiation of the view, i.e.
  * in the plugin loading phase.  Since there is no way to inject view
  * helpers into the view object, this helper object cannot be instantiated
  * and registered for use by the add_mime_display_type() function.
  * 
  * @param array|string $fileIdentifiers Set of MIME types (Internet media 
  * types) and/or file extensions that this specific callback will respond 
  * to. Accepts the following:
  * <ul>
  *     <li>A string containing one MIME type: 
  *     <code>'application/msword'</code></li>
  *     <li>A simple array containing MIME types: 
  *     <code>array('application/msword', 'application/doc')</code></li>
  *     <li>A keyed array containing MIME types: 
  *     <code>array('mimeTypes' => array('application/msword', 'application/doc'))</code></li>
  *     <li>A keyed array containing file extensions: 
  *     <code>array('fileExtensions' => array('doc', 'docx''DOC', 'DOCX'))</code></li>
  *     <li>A keyed array containing MIME types and file extensions: <code>
  *     array(
  *         'mimeTypes' => array(
  *             'application/msword', 
  *             'application/doc', 
  *             'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 
  *         ), 
  *         'fileExtensions' => array('doc', 'docx', 'DOC', 'DOCX'), 
  *     )
  *     </code></li>
  * </ul>
  * Note that file extensions are case sensitive.
  * @param callback Any valid callback.  This function should return a string 
  * containing valid XHTML, which will be used to display the file.
  * @param array $defaultOptions
  * @param array $fileExtensions
  * @return void
  */
 public static function addMimeTypes($fileIdentifiers, $callback, array $defaultOptions = array())
 {
     // Create the keyed list of mimeType => callback and fileExtension =>
     // callback format, and merge them with the current lists.
     $callbackListMimeTypes = array();
     $callbackListFileExtensions = array();
     // Interpret string as MIME type.
     if (is_string($fileIdentifiers)) {
         $fileIdentifiers = (array) $fileIdentifiers;
         $fillArray = array_fill(0, count($fileIdentifiers), $callback);
         $callbackListMimeTypes = array_combine($fileIdentifiers, $fillArray);
     } else {
         if (is_array($fileIdentifiers)) {
             // Interpret unkeyed array as MIME types.
             if (array_key_exists(0, $fileIdentifiers)) {
                 $fillArray = array_fill(0, count($fileIdentifiers), $callback);
                 $callbackListMimeTypes = array_combine($fileIdentifiers, $fillArray);
                 // Interpret keyed array as MIME types and/or file extensions.
             } else {
                 if (array_key_exists('mimeTypes', $fileIdentifiers)) {
                     $fillArray = array_fill(0, count($fileIdentifiers['mimeTypes']), $callback);
                     $callbackListMimeTypes = array_combine($fileIdentifiers['mimeTypes'], $fillArray);
                 }
                 if (array_key_exists('fileExtensions', $fileIdentifiers)) {
                     $fillArray = array_fill(0, count($fileIdentifiers['fileExtensions']), $callback);
                     $callbackListFileExtensions = array_combine($fileIdentifiers['fileExtensions'], $fillArray);
                 }
             }
         }
     }
     self::$_callbacks = array_merge(self::$_callbacks, $callbackListMimeTypes);
     self::$_fileExtensionCallbacks = array_merge(self::$_fileExtensionCallbacks, $callbackListFileExtensions);
     // Add this callback's default options to the list.
     $key = self::_getCallbackKey($callback);
     self::$_callbackOptions[$key] = $defaultOptions;
 }
コード例 #2
0
/**
 * Get a customized file image tag.
 *
 * @since 2.2
 * @package Omeka\Function\View\File
 * @uses Omeka_View_Helper_FileMarkup::image_tag()
 * @param string $imageType Image size: thumbnail, square thumbnail, fullsize
 * @param array $props HTML attributes for the img tag.
 * @param File|null Check for this specific file record (current file if null).
 */
function file_image($imageType, $props = array(), $file = null)
{
    if (!$file) {
        $file = get_current_record('file');
    }
    $fileMarkup = new Omeka_View_Helper_FileMarkup();
    return $fileMarkup->image_tag($file, $props, $imageType);
}
コード例 #3
0
 public function hookInitialize($args)
 {
     Omeka_View_Helper_FileMarkup::addMimeTypes(array('application/xml', 'text/xml'), 'TeiDisplayPlugin::TeiDisplay');
     Omeka_View_Helper_FileMarkup::addMimeTypes('text/x-c', 'TeiDisplayPlugin::CssDisplay');
 }