? .cdn.admin.inc.swp
? .cdn.module.swp
? .swp
? cdn_media_mover.patch
Index: cdn.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/cdn/cdn.admin.inc,v
retrieving revision 1.2
diff -u -p -w -r1.2 cdn.admin.inc
--- cdn.admin.inc	2 Feb 2010 17:06:03 -0000	1.2
+++ cdn.admin.inc	12 Feb 2010 21:25:31 -0000
@@ -39,6 +39,10 @@ function cdn_admin_settings_form() {
       "<strong>Basic mode</strong> will simply prepend another URL to the
       complete file URL. Therefor, it only works for CDNs that support the
       Origin Pull technique.<br />
+      <strong>Media Mover mode</strong> uses the URLs stored in the Media 
+      Mover module's files table to rewrite the image paths based on whether or
+      not the files have been pushed to the CDN. This method only supports push 
+      CDNs such as Amazon S3.<br />
       <strong>Advanced mode</strong> uses the daemon to synchronize files and
       can be used with both Origin Pull and Push CDNs. If you've got an Origin
       Pull CDN and want to process files before they're synced to the CDN, it
@@ -46,6 +50,7 @@ function cdn_admin_settings_form() {
     ),
     '#options' => array(
       CDN_MODE_BASIC    => t('Basic'),
+      CDN_MODE_MEDIAMOVER => t('Media Mover'),
       CDN_MODE_ADVANCED => t('Advanced'),
     ),
     '#default_value' => variable_get(CDN_MODE_VARIABLE, CDN_MODE_BASIC),
@@ -128,6 +133,22 @@ function cdn_admin_basic_settings_form()
 }
 
 /**
+ * Form definition; Media Mover settings.
+ */
+function cdn_admin_media_mover_settings_form() {
+  $form['cdn_media_mover_api_version'] = array(
+    '#title'         => t('Media Mover API version'),
+    '#type'          => 'textfield',
+    '#disabled'          => TRUE,
+    '#description'   => t('Automatically detected when Media Mover mode is selected. Re-submit 
+                           the main settings form to refresh this setting.'),
+    '#default_value' => variable_get(CDN_MEDIAMOVER_API_VARIABLE, _cdn_get_media_mover_api_version()),
+  );
+  
+  return system_settings_form($form);
+}
+
+/**
  * Form definition; advanced settings.
  */
 function cdn_admin_advanced_settings_form() {
@@ -181,17 +202,32 @@ function cdn_admin_other_settings_form()
  * Default validate callback for the settings form.
  */
 function cdn_admin_settings_form_validate($form, &$form_state) {
+  $enabled  = isset($form_state['values'][CDN_STATUS_VARIABLE]) && $form_state['values'][CDN_STATUS_VARIABLE] != CDN_DISABLED;
+  $media_mover = isset($form_state['values'][CDN_MODE_VARIABLE]) && $form_state['values'][CDN_MODE_VARIABLE]   == CDN_MODE_MEDIAMOVER;
+  $advanced = isset($form_state['values'][CDN_MODE_VARIABLE]) && $form_state['values'][CDN_MODE_VARIABLE]   == CDN_MODE_ADVANCED;
+  if ($enabled) {
+    if ($advanced) {
   // Validate the synced files DB whenever advanced mode is enabled. It must
   // be configured (on the advanced settings form) *before* advanced mode can
   // be enabled!
-  $enabled  = isset($form_state['values'][CDN_STATUS_VARIABLE]) && $form_state['values'][CDN_STATUS_VARIABLE] != CDN_DISABLED;
-  $advanced = isset($form_state['values'][CDN_MODE_VARIABLE])   && $form_state['values'][CDN_MODE_VARIABLE]   == CDN_MODE_ADVANCED;
-  if ($enabled && $advanced) {
     $synced_files_db = variable_get(CDN_ADVANCED_SYNCED_FILES_DB_VARIABLE, '');
     if (!_validate_synced_files_db($synced_files_db, CDN_STATUS_VARIABLE)) {
       drupal_set_message(t('Please correct the above error in the <em>Advanced mode</em> settings form first.'), 'error');
     }
   }
+    elseif ($media_mover) {
+      $mm_version = _cdn_get_media_mover_api_version();
+      switch($mm_version) {
+      case 1:
+      case 2:
+        variable_set(CDN_MEDIAMOVER_API_VARIABLE, $mm_version[1]);
+        drupal_set_message(t('Using Media Mover API version ' . $mm_version), 'status');
+        break;
+      default:
+        drupal_set_message(t('Could not detect Media Mover API version.'), 'error');
+      }
+    }
+  }
 }
 
 /**
@@ -241,3 +277,9 @@ function _validate_synced_files_db($sync
 
   return TRUE;
 }
+
+function _cdn_get_media_mover_api_version() {
+  $mm_info = unserialize(db_result(db_query("SELECT info FROM system WHERE name = 'media_mover_api'")));
+  preg_match('/[0-9]\..-([0-9])/', $mm_info['version'], $matches);
+  return $matches[1];
+}
Index: cdn.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/cdn/cdn.module,v
retrieving revision 1.33
diff -u -p -w -r1.33 cdn.module
--- cdn.module	4 Feb 2010 00:30:34 -0000	1.33
+++ cdn.module	12 Feb 2010 21:25:31 -0000
@@ -18,6 +18,7 @@ define('CDN_PERM_ACCESS_DEBUG', 'access 
 // Variables and values.
 define('CDN_MODE_VARIABLE', 'cdn_mode');
 define('CDN_MODE_BASIC', 'basic');
+define('CDN_MODE_MEDIAMOVER', 'media_mover');
 define('CDN_MODE_ADVANCED', 'advanced');
 define('CDN_STATUS_VARIABLE', 'cdn_status');
 define('CDN_STATS_VARIABLE', 'cdn_stats');
@@ -30,6 +31,9 @@ define('CDN_BASIC_URL_VARIABLE', 'cdn_ba
 define('CDN_BASIC_EXTENSIONS_VARIABLE', 'cdn_basic_extensions');
 define('CDN_BASIC_EXTENSIONS_DEFAULT', '.css .js .ico .gif .jpg .jpeg .png .svg .otf .ttf .swf');
 
+// Variables for media mover mode.
+define('CDN_MEDIAMOVER_API_VARIABLE', 'cdn_media_mover_api_version');
+
 // Variables for advanced mode.
 define('CDN_ADVANCED_SYNCED_FILES_DB_VARIABLE', 'cdn_advanced_synced_files_db');
 
@@ -75,6 +79,9 @@ function cdn_file_url_alter(&$path) {
       $cdn_url = cdn_basic_get_url($path);
       $server = FALSE;
     }
+    elseif ($mode == CDN_MODE_MEDIAMOVER) {
+      $cdn_url = cdn_media_mover_get_url($path);
+    }
     else {
       list($cdn_url, $server) = cdn_advanced_get_url($path);
     }
@@ -124,6 +131,16 @@ function cdn_menu() {
     'type'             => MENU_LOCAL_TASK,
     'file'             => 'cdn.admin.inc',
   );
+  $items['admin/settings/cdn/media_mover'] = array(
+    'title'            => 'Media Mover mode',
+    'description'      => 'Media Mover settings.',
+    'access arguments' => array('administer site configuration'),
+    'page callback'    => 'drupal_get_form',
+    'page arguments'   => array('cdn_admin_media_mover_settings_form'),
+    'weight'           => -8,
+    'type'             => MENU_LOCAL_TASK,
+    'file'             => 'cdn.admin.inc',
+  );
   $items['admin/settings/cdn/advanced'] = array(
     'title'            => 'Advanced mode',
     'description'      => 'Advanced mode settings.',
@@ -404,6 +421,30 @@ function cdn_basic_get_url($path) {
 }
 
 /**
+ * Gets the URL for a file when the Media mover mode is enabled.
+ *
+ * @param $path
+ *   The path to get the URL for.
+ */
+function cdn_media_mover_get_url($path) {
+  $mm_api_version = variable_get('cdn_media_mover_api_version', '');
+
+  if ($mm_api_version == 1) {
+    // Check if $path is in the media mover db and get the path at the last step if so.
+    $complete_file = db_result(db_query("SELECT complete_file FROM media_mover_files WHERE harvest_file = '%s'", $path));
+    // Only use if $complete_file is an external URL.
+    $data = explode('://', $complete_file);
+    if (count($data) == 2) {
+      $cdn_url = $complete_file;
+    }
+  }
+  elseif ($mm_api_version == 2) {
+    // TODO
+  }
+  return $cdn_url ? $cdn_url : $path;
+}
+
+/**
  * Gets the URL for a file when the basic mode is enabled.
  *
  * @param $path
