| 1 |
<?php |
<?php |
| 2 |
// $Id: http_headers.module,v 1.1 2008/04/14 20:22:09 matslats Exp $ |
// $Id$ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 20 |
/** |
/** |
| 21 |
* Implementation of hook_form_alter(). |
* Implementation of hook_form_alter(). |
| 22 |
*/ |
*/ |
| 23 |
function http_headers_form_alter($form_id, &$form){ |
function http_headers_form_alter(&$form, $form_state, $form_id){ |
| 24 |
if ( $form_id == "node_type_form"){ |
if ( $form_id == "node_type_form"){ |
| 25 |
//get the values from the database |
//get the values from the database |
| 26 |
$h=http_headers_getType($form['#node_type']-> type); |
$h=http_headers_getType($form['#node_type']-> type); |
| 55 |
'#description'=> 'The users browser should only reload the page if drupal reports it was modified after this date.' |
'#description'=> 'The users browser should only reload the page if drupal reports it was modified after this date.' |
| 56 |
) |
) |
| 57 |
); |
); |
| 58 |
$form['#submit']['http_headers_form_submit']=array(); |
$form['#submit'][]='http_headers_form_submit'; |
| 59 |
} |
} |
| 60 |
return $form; |
return $form; |
| 61 |
} |
} |
| 62 |
|
|
| 63 |
function http_headers_form_submit($form_id, $form_values){ |
function http_headers_form_submit($form, $form_state){ |
| 64 |
//drupal_set_message($form_values['header_lastmod'].$form_values['type']); |
$t=$form['#node_type']->type; |
| 65 |
db_query("UPDATE {node_type} SET header_lastmod = '%s' WHERE type = '%s'", $form_values['header_lastmod'], $form_values['type']); |
$result=db_query("UPDATE {node_type} SET header_lastmod = '%s' WHERE type = '%s'", $form['#post']['header_lastmod'], $t); |
| 66 |
db_query("UPDATE {node_type} SET header_expires = %d WHERE type = '%s'", $form_values['header_expires'], $form_values['type']); |
if (!$result){ |
| 67 |
|
drupal_set_messsage("Failed to set Last-Modified header"); |
| 68 |
|
} |
| 69 |
|
$result=db_query("UPDATE {node_type} SET header_expires = %d WHERE type = '%s'", $form['#post']['header_expires'], $t); |
| 70 |
|
if (!$result){ |
| 71 |
|
drupal_set_messsage("Failed to set Expires header"); |
| 72 |
|
} |
| 73 |
} |
} |
| 74 |
|
|
| 75 |
|
|
| 78 |
//set the headers according to the contentType of the node |
//set the headers according to the contentType of the node |
| 79 |
//This didn't fire for some reason so I used nodeapi, below. |
//This didn't fire for some reason so I used nodeapi, below. |
| 80 |
*/ |
*/ |
| 81 |
function http_headers_load($node) { |
function http_headers_load() { |
| 82 |
//drupal_set_message("hook function http_headers_load fired!"); |
|
| 83 |
} |
} |
| 84 |
|
|
| 85 |
function http_headers_nodeapi($node, $op) { |
function http_headers_nodeapi($node, $op) { |
| 86 |
if ($op=="load" && arg(0)=="node"){ |
if ($op=="load" && arg(0)=="node"){ |
| 87 |
|
drupal_set_message("This web site is testing a new Drupal module to improve performance for users with a poor connection by modifying the http headers:"); |
| 88 |
$h=http_headers_getType($node ->type); |
$h=http_headers_getType($node ->type); |
| 89 |
if ($h['header_expires']){ |
if ($h['header_expires']){ |
| 90 |
$expiry=date("D, d M Y G:i:s T", time() + $h['header_expires']); |
$expiry=date("D, d M Y G:i:s T", time() + $h['header_expires']); |