--- nopremium.module_orig	2012-03-16 17:10:57.478723098 +0900
+++ nopremium.module	2012-03-16 19:15:25.842855390 +0900
@@ -121,6 +121,58 @@
 
 
 /**
+ * Implementation of hook_file_download().
+ * - most of code from file_file_download() -
+ */
+function nopremium_file_download($uri, $field_type = 'file') {
+  // Get the file record based on the URI. If not in the database just return.
+  $files = file_load_multiple(array(), array('uri' => $uri));
+  if (count($files)) {
+    foreach ($files as $item) {
+      // Since some database servers sometimes use a case-insensitive comparison
+      // by default, double check that the filename is an exact match.
+      if ($item->uri === $uri) {
+        $file = $item;
+        break;
+      }
+    }
+  }
+  if (!isset($file)) {
+    return;
+  }
+
+  // Find out which (if any) fields of this type contain the file.
+  $references = file_get_file_references($file, NULL, FIELD_LOAD_CURRENT, $field_type);
+
+  // Loop through all references of this file. If a reference explicitly denies 
+  // access to the field to which this file belongs, according to nopremium_access, 
+  // no further checks are done and download access is denied.
+  foreach ($references as $field_name => $field_references) {
+    if (!empty($field_references['node'])) {
+      foreach ($field_references['node'] as $nid => $reference) {
+        $entity = entity_load('node', array($nid));
+        $entity = reset($entity);
+        $field = field_info_field($field_name);
+        // Load the field item that references the file if it's premium.
+        if ($entity && $entity->premium) {
+          // Load all field items for that entity.
+          $field_items = field_get_items('node', $entity, $field_name);
+
+          // Find the field item with the matching URI.
+          foreach ($field_items as $item) {
+            if ($item['uri'] == $uri) {
+              if ( !nopremium_access_full_content($entity) ) { return -1; }
+            }
+          }
+        }
+      }
+    }
+  }
+}
+
+
+
+/**
  * Implementation of hook_node_prepare().
  * Set up premium default value, if required.
  */

