/[drupal]/contributions/modules/filerequest/filerequest.module
ViewVC logotype

Diff of /contributions/modules/filerequest/filerequest.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.3, Tue Mar 7 20:48:24 2006 UTC revision 1.4, Mon Jul 3 14:03:54 2006 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: filerequest.module,v 1.2 2006/01/06 16:38:38 elmuerte Exp $  // $Id: filerequest.module,v 1.2.2.2 2006/03/26 15:08:08 elmuerte Exp $
3    
4  function filerequest_help($section) {  function filerequest_help($section) {
5    switch ($section) {    switch ($section) {
6      case 'admin/modules#description':      case 'admin/modules#description':
7        return t('properly handles file requests for download method "private"');        return t('Properly handles file requests for download method "private". Also provides anti leeching features.');
8    }    }
9  }  }
10    
# Line 29  function filerequest_menu($may_cache) { Line 29  function filerequest_menu($may_cache) {
29   * Show settings. Used for anti-leech and config file generation   * Show settings. Used for anti-leech and config file generation
30   */   */
31  function filerequest_settings() {  function filerequest_settings() {
32    $output = "";    $form['settings'] = array(
33        '#type' => 'fieldset',
34        '#title' => t('filerequest settings'),
35      );
36    
37      $form['settings']['filereq_antileech_enabled'] = array(
38        '#type' => 'checkbox',
39        '#title' => t('Anti-leech enabled'),
40        '#return_value' => 1,
41        '#default_value' => variable_get('filereq_antileech_enabled', true),
42        '#description' => t('Prevent other sites from directly linking to files'),
43      );
44    
45      $form['settings']['filereq_antileech_regex'] = array(
46        '#type' => 'textfield',
47        '#title' => t('Valid host'),
48        '#default_value' => variable_get('filereq_antileech_regex', preg_quote($_SERVER["HTTP_HOST"])),
49        '#size' => 72,
50        '#maxlength' => 65535,
51        '#description' => t('A regular expression defining hosts that are allowed to directly link to the file. This should at least cover the current host.'),
52      );
53    
54      $opts[0] = "Normal";
55      $opts[1] = "Add a watermark";
56      $opts[2] = "Replace the image";
57      $form['settings']['filereq_antileech_image_mode'] = array(
58        '#type' => 'select',
59        '#title' => t('Image mode'),
60        '#default_value' => variable_get('filereq_antileech_image_mode', 0),
61        '#options' => $opts,
62        '#description' => t('Special behavior when leeching images.'),
63      );
64    
65      $form['settings']['filereq_antileech_image_file'] = array(
66        '#type' => 'textfield',
67        '#title' => t('Image file'),
68        '#default_value' => variable_get('filereq_antileech_image_file', ""),
69        '#size' => 72,
70        '#maxlength' => 65535,
71        '#description' => t('The image to used when special image handling is enabled. This path is relative to the drupal base directory. <br />In case of the watermark mode the image has to be a 24 bit PNG file. Hint: make use of the alpha channels for PNGs.'),
72      );
73    
74      $form['config'] = array(
75        '#type' => 'fieldset',
76        '#title' => t('modules/filerequest/throttle.config.php'),
77        '#description' => t('Use the following configuration if you added the .htaccess lines as provided in the README.TXT .')
78      );
79    
80      $form['config'][] = array(
81        '#value' => "<textarea rows=\"7\" cols=\"72\" readonly=\"readonly\" wrap=\"off\"><?php\n\$config[\"filereq_antileech_enabled\"] = ".variable_get('filereq_antileech_enabled', true).";\n\$config[\"filereq_antileech_regex\"] = \"".addslashes(variable_get('filereq_antileech_regex', preg_quote($_SERVER["HTTP_HOST"])))."\";\n\$config[\"filereq_fspath\"] = \"".addslashes(file_create_path())."\";\n\$config[\"filereq_antileech_image_mode\"] = ".variable_get('filereq_antileech_image_mode', 0).";\n\$config[\"filereq_antileech_image_file\"] = \"".addslashes(variable_get('filereq_antileech_image_file', "modules/filerequest/watermark.png"))."\";\n?></textarea>"
82      );
83    
84    $output .= form_checkbox(t('Anti-leech enabled'), 'filereq_antileech_enabled', 1, variable_get('filereq_antileech_enabled', true), t('Prevent other sites from directly linking to files'));    return $form;
   $output .= form_textfield(t('Valid host'), 'filereq_antileech_regex', variable_get('filereq_antileech_regex', preg_quote($_SERVER["HTTP_HOST"])), 72, 65535, t('A regular expression defining hosts that are allowed to directly link to the file. This should at least cover the current host.'));  
   
   $output = form_group(t('filerequest settings'), $output, t(''));  
   
   $tcfg = t('Use the following configuration if you added the .htaccess lines as provided in the README.TXT .');  
   $tcfg .= "<br /><textarea rows=\"5\" cols=\"72\" readonly=\"readonly\" wrap=\"off\"><?php\n\$config[\"filereq_antileech_enabled\"] = ".variable_get('filereq_antileech_enabled', true).";\n\$config[\"filereq_antileech_regex\"] = \"".addslashes(variable_get('filereq_antileech_regex', preg_quote($_SERVER["HTTP_HOST"])))."\";\n\$config[\"filereq_fspatch\"] = \"".addslashes(file_create_path())."\";\n?></textarea>";  
   
   $output .= form_group(t('modules/filerequest/throttle.config.php'), $tcfg, t(''));  
   return $output;  
85  }  }
86    
87  /**  /**
# Line 48  function filerequest_settings() { Line 89  function filerequest_settings() {
89   * associated node, otherwise return an access_denied error.   * associated node, otherwise return an access_denied error.
90   */   */
91  function _filerequest_download() {  function _filerequest_download() {
92      define("__DRUPAL_BASE_DIR", dirname(dirname(dirname(__FILE__))).DIRECTORY_SEPARATOR);
93    require_once("downloadhandler.php");    require_once("downloadhandler.php");
   $file = $_GET['file'];  
94    
95      $config["filename"] = $_GET['file'];
96    $config["filereq_antileech_enabled"] = variable_get('filereq_antileech_enabled', true);    $config["filereq_antileech_enabled"] = variable_get('filereq_antileech_enabled', true);
97    $config["filereq_antileech_regex"] = variable_get('filereq_antileech_regex', preg_quote($_SERVER["HTTP_HOST"]));    $config["filereq_antileech_regex"] = variable_get('filereq_antileech_regex', preg_quote($_SERVER["HTTP_HOST"]));
98      $config["filereq_antileech_image_mode"] = variable_get('filereq_antileech_image_mode', 0);
99      $config["filereq_antileech_image_file"] = variable_get('filereq_antileech_image_file', "modules/filerequest/watermark.png");
100    
101    if (!__anti_leech($config)) define("__FILEREQ_LEECH", $file);    if (!__fr_can_download_file($config)) define("__FILEREQ_LEECH", $file);
102    
103    if (defined("__FILEREQ_LEECH"))    if (defined("__FILEREQ_LEECH"))
104    {    {
105      $result = db_result(db_query("SELECT nid FROM {files} WHERE filepath = '%s'", $file));      $result = db_result(db_query("SELECT nid FROM {files} WHERE filepath = '%s'", $config["filename"]));
106      if ($result !== false)      if ($result !== false)
107      {      {
108        drupal_goto("node/".$result);        drupal_goto("node/".$result);
# Line 67  function _filerequest_download() { Line 111  function _filerequest_download() {
111      drupal_access_denied();      drupal_access_denied();
112      return;      return;
113    }    }
114    $filepath = file_create_path($file);    $config["filename"] = file_create_path($config["filename"]);
115    if (file_exists($filepath)) {    if (file_exists($config["filename"])) {
116      $list = module_list();      $list = module_list();
117      foreach ($list as $module) {      foreach ($list as $module) {
118        $headers = module_invoke($module, 'file_download', $file);        $headers = module_invoke($module, 'file_download', $_GET['file']);
119        if ($headers === -1) {        if (in_array(-1, $headers)) {
120          drupal_access_denied();          return drupal_access_denied();
121        }        }
122        elseif (is_array($headers)) {        elseif (is_array($headers)) {
123          // make sure no caching headers are set          // make sure no caching headers are set
124          header("Cache-Control:");          header("Cache-Control:");
125          header("Pragma:");          header("Pragma:");
126          header("Expires:");          header("Expires:");
127          process_download($filepath);          __fr_process_download($config["filename"], preg_match("#(\?|&)download(&|$)#", $_SERVER["REQUEST_URI"]), $config["watermark"]);
128          exit();          exit();
129        }        }
130      }      }
131    }    }
132    drupal_not_found();    drupal_not_found();
133  }  }
   
 ?>  

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

  ViewVC Help
Powered by ViewVC 1.1.2