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

Diff of /contributions/modules/http_action/http_action.module

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

revision 1.2, Tue Jul 31 06:18:30 2007 UTC revision 1.3, Tue Jul 31 21:29:05 2007 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id$  // $Id: http_action.module,v 1.2 2007/07/31 06:18:30 eaton Exp $
3    
4  /**  /**
5   * @file   * @file
# Line 61  function http_action_request_action_form Line 61  function http_action_request_action_form
61      '#default_value' => $context['headers'],      '#default_value' => $context['headers'],
62      '#columns'       => 80,      '#columns'       => 80,
63      '#rows'          => 3,      '#rows'          => 3,
64      '#description' => t('Any additional headers that should be sent with the request. One line per header, with the header name and a colon at the beginning of each line. You may also use the following variables: %site_name, %username, %node_url, %node_type, %title, %teaser, %body. Not all variables will be available in all contexts.'),      '#description' => t('Any additional headers that should be sent with the request. One line per header, with the header name and a colon at the beginning of each line.'),
65      '#required'      => FALSE,      '#required'      => FALSE,
66    );    );
67    
# Line 71  function http_action_request_action_form Line 71  function http_action_request_action_form
71      '#default_value' => $context['data'],      '#default_value' => $context['data'],
72      '#columns'       => 80,      '#columns'       => 80,
73      '#rows'          => 3,      '#rows'          => 3,
74      '#description'   => t('Optionally, any data that should be sent with the request. You may use the following variables: %site_name, %username, %node_url, %node_type, %title, %teaser, %body. Not all variables will be available in all contexts.'),      '#description'   => t('Optionally, any data that should be sent with the request.'),
75      '#required'      => FALSE,      '#required'      => FALSE,
76    );    );
77    
78      if (module_exists('token')) {
79        $form['help'] = array(
80          '#type' => 'fieldset',
81          '#collapsible' => TRUE,
82          '#collapsed' => TRUE,
83          '#title' => t('Placeholder tokens'),
84          '#description' => t("The following placeholder tokens can be used in any of the above fields. Some tokens may not be available, depending on the context in which the action is triggered."),
85        );
86    
87        $form['help']['tokens'] = array(
88          '#value' => theme('token_help', 'all'),
89        );
90      }
91    
92    return $form;    return $form;
93  }  }
94    
# Line 96  function http_action_request_action_subm Line 110  function http_action_request_action_subm
110   * Sends an email.   * Sends an email.
111   */   */
112  function http_action_request_action($object, $context) {  function http_action_request_action($object, $context) {
113    global $user;    $context['global'] = NULL;
   $variables['%site_name'] = variable_get('site_name', 'Drupal');  
   
   switch ($context['hook']) {  
     case 'nodeapi':  
       // Because this is not an action of type 'node' the node  
       // will not be passed as $object, but it will still be available  
       // in $context.  
       $node = $context['node'];  
       break;  
     // The comment hook provides nid, in $context.  
     case 'comment':  
       $comment = $context['comment'];  
       $node = node_load($comment->nid);  
     case 'user':  
       // Because this is not an action of type 'user' the user  
       // object is not passed as $object, but it will still be available  
       // in $context.  
       $account = $context['account'];  
       if (isset($context['node'])) {  
         $node = $context['node'];  
       }  
       elseif ($context['recipient'] == '%author') {  
         // If we don't have a node, we don't have a node author.  
         watchdog('error', 'Cannot use %author token in this context.');  
         return;  
       }  
       break;  
     case 'taxonomy':  
       $account = $user;  
       $vocabulary = taxonomy_vocabulary_load($object->vid);  
       $variables = array_merge($variables, array(  
         '%term_name' => $object->name,  
         '%term_description' => $object->description,  
         '%term_id' => $object->tid,  
         '%vocabulary_name' => $vocabulary->name,  
         '%vocabulary_description' => $vocabulary->description,  
         '%vocabulary_id' => $vocabulary->vid,  
         )  
       );  
       break;  
     default:  
       // We are being called directly.  
       $node = $object;  
   }  
114    
115    if (!empty($account)) {    $uri = token_replace_multiple($context['uri'], $context);
116      $variables['%username'] = $account->name;    $data = token_replace_multiple($context['data'], $context);
   }  
   
   // Node-based variable translation is only available if we have a node.  
   if (isset($node) && is_object($node)) {  
     $variables = array_merge($variables, array(  
         '%uid' => $node->uid,  
         '%node_url' => url('node/'. $node->nid, array('absolute' => TRUE)),  
         '%node_type' => node_get_types('name', $node),  
         '%title' => $node->title,  
         '%teaser' => $node->teaser,  
         '%body' => $node->body  
       )  
     );  
   }  
117    
118    $uri = strtr($context['uri'], $variables);    $tmp = token_replace_multiple($context['headers'], $context);
   $headers = array();  
   $data = strtr($context['data'], $variables);  
   
   $tmp = strtr($context['headers'], $variables);  
119    $lines = explode("\n", $tmp);    $lines = explode("\n", $tmp);
120      $headers = array();
121    foreach ($lines as $line) {    foreach ($lines as $line) {
122      $foo = explode(':', $line, 2);      $foo = explode(':', $line, 2);
123      $headers[$foo[0]] = trim($foo[1]);      $headers[$foo[0]] = trim($foo[1]);

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

  ViewVC Help
Powered by ViewVC 1.1.2