<?php
// $Id$

/**
 * Gives the list of transforms available for a given extension.
 *
 * @param $ext
 *   The extension.
 * @return 
 *   An associative array with name of the transform as the key, the include
 *   as the include file.
 */
function mapi_transform_by_ext($ext) {
  $transforms = array();  
  foreach (mapi_transform_list() as $transform) {
    $exts = mapi_extension_by_transform($transform);
    if (is_array($exts) && in_array($ext, $exts)) {
      $transforms[] = $transform;
    }
  }
  return $transforms;
}

/**
 * Provides list of presenters, with the extensions support, with the include file for each.
 *
 * @return 
 *   Double associative array. First level keys are the presenter names, and the second level
 *   keys are the extensions. The values are the include files for each.
 */
function mapi_transform_list() {
  return mapi_invoke_transforms('list');
}

/**
 * Provides a list of extensions which exist for a given transforms.
 *
 * @param $name
 *   The name of the presenter for which the transforms exist.
 * @return 
 *   An associative array with extension is the key, and the include is the value.
 */
function mapi_extension_by_transform($name) {
  return mapi_invoke_transforms('list', $name);
}

/**
 * Performs the transform on a file to another file
 *
 */
function mapi_transform_execute($source, $dest, $name, $settings) {
  if (!is_file($source) || !in_array($name, mapi_transform_list()) || ($source == $dest)) {
    return FALSE;
  }
  return mapi_invoke_transforms('transform', $name, array('dest' => $dest, 'settings' => $settings), $source);
}
