/[drupal]/drupal/modules/upload/upload.tokens.inc
ViewVC logotype

Contents of /drupal/modules/upload/upload.tokens.inc

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


Revision 1.1 - (show annotations) (download) (as text)
Wed Aug 19 20:19:37 2009 UTC (3 months ago) by dries
Branch: MAIN
CVS Tags: DRUPAL-7-0-UNSTABLE-9, DRUPAL-7-0-UNSTABLE-10, HEAD
File MIME type: text/x-php
- Patch #113614 by eaton, fago, et al: add centralized token/placeholder subsituation to core.
1 <?php
2 // $Id: upload.tokens.inc,v 1.9 2009/07/12 16:27:54 eaton Exp $
3
4 /**
5 * @file
6 * Builds placeholder replacement tokens for uploaded files attached to nodes.
7 */
8
9 /**
10 * Implement hook_token_info().
11 */
12 function upload_token_info() {
13 $results['tokens']['node'] = array(
14 'upload' => array(
15 'name' => t('File attachment'),
16 'description' => t('The first file attached to a node, if one exists.'),
17 'type' => 'file',
18 )
19 );
20 return $results;
21 }
22
23 /**
24 * Implement hook_tokens().
25 */
26 function upload_tokens($type, $tokens, array $data = array(), array $options = array()) {
27 $replacements = array();
28
29 if ($type == 'node' && !empty($data['node'])) {
30 $node = $data['node'];
31
32 foreach ($tokens as $name => $original) {
33 if ($name == 'upload') {
34 $upload = array_shift($node->files);
35 $replacements[$original] = file_create_url($upload->filepath);
36 }
37 }
38
39 if (($upload_tokens = token_find_with_prefix($tokens, 'upload')) && !empty($node->files) && $upload = array_shift($node->files)) {
40 $replacements += token_generate('file', $upload_tokens, array('file' => $upload), $options);
41 }
42 }
43
44 return $replacements;
45 }

  ViewVC Help
Powered by ViewVC 1.1.2