diff options
author | Angie Byron <webchick@24967.no-reply.drupal.org> | 2010-04-20 09:48:06 +0000 |
---|---|---|
committer | Angie Byron <webchick@24967.no-reply.drupal.org> | 2010-04-20 09:48:06 +0000 |
commit | 7bb6753e9fc8d89472ecc2b6d5ab670dde27b935 (patch) | |
tree | 79eae1caf8b93351560fa36202d46913ac06e1ef /modules/system/system.tokens.inc | |
parent | 8e94b5d6d400d33c0f840a7ae97ff8a715272a79 (diff) | |
download | brdo-7bb6753e9fc8d89472ecc2b6d5ab670dde27b935.tar.gz brdo-7bb6753e9fc8d89472ecc2b6d5ab670dde27b935.tar.bz2 |
#701818 by mcarbone: Test coverage of every core token, and bug fixes to make them work. AWESOME! :D
Diffstat (limited to 'modules/system/system.tokens.inc')
-rw-r--r-- | modules/system/system.tokens.inc | 53 |
1 files changed, 14 insertions, 39 deletions
diff --git a/modules/system/system.tokens.inc b/modules/system/system.tokens.inc index e86bf8490..501ab8fd5 100644 --- a/modules/system/system.tokens.inc +++ b/modules/system/system.tokens.inc @@ -76,7 +76,7 @@ function system_token_info() { ); $date['since'] = array( 'name' => t("Time-since"), - 'description' => t("A data in 'time-since' format. (%date)", array('%date' => format_interval(REQUEST_TIME - 360, 2))), + 'description' => t("A date in 'time-since' format. (%date)", array('%date' => format_interval(REQUEST_TIME - 360, 2))), ); $date['raw'] = array( 'name' => t("Raw timestamp"), @@ -93,10 +93,6 @@ function system_token_info() { 'name' => t("User ID"), 'description' => t("The unique ID of the user who owns the file."), ); - $file['nid'] = array( - 'name' => t("Node ID"), - 'description' => t("The unique ID of the node the file is attached to."), - ); $file['name'] = array( 'name' => t("File name"), 'description' => t("The name of the file on disk."), @@ -107,7 +103,7 @@ function system_token_info() { ); $file['path'] = array( 'name' => t("Path"), - 'description' => t("The location of the file on disk."), + 'description' => t("The location of the file relative to Drupal root."), ); $file['mime'] = array( 'name' => t("MIME type"), @@ -117,7 +113,7 @@ function system_token_info() { 'name' => t("File size"), 'description' => t("The size of the file, in kilobytes."), ); - $file['path'] = array( + $file['url'] = array( 'name' => t("URL"), 'description' => t("The web-accessible URL for the file."), ); @@ -126,11 +122,6 @@ function system_token_info() { 'description' => t("The date the file was most recently changed."), 'type' => 'date', ); - $file['node'] = array( - 'name' => t("Node"), - 'description' => t("The node the file is attached to."), - 'type' => 'date', - ); $file['owner'] = array( 'name' => t("Owner"), 'description' => t("The user who originally uploaded the file."), @@ -155,6 +146,7 @@ function system_tokens($type, $tokens, array $data = array(), array $options = a if (isset($language)) { $url_options['language'] = $language; } + $langcode = (isset($language) ? $language->language : NULL); $sanitize = !empty($options['sanitize']); $replacements = array(); @@ -203,14 +195,9 @@ function system_tokens($type, $tokens, array $data = array(), array $options = a else { $date = $data['date']; } - $langcode = (isset($language) ? $language->language : NULL); foreach ($tokens as $name => $original) { switch ($name) { - case 'raw': - $replacements[$original] = filter_xss($date); - break; - case 'short': $replacements[$original] = format_date($date, 'short', '', NULL, $langcode); break; @@ -226,6 +213,10 @@ function system_tokens($type, $tokens, array $data = array(), array $options = a case 'since': $replacements[$original] = format_interval((REQUEST_TIME - $date), 2, $langcode); break; + + case 'raw': + $replacements[$original] = filter_xss($date); + break; } } @@ -250,10 +241,6 @@ function system_tokens($type, $tokens, array $data = array(), array $options = a $replacements[$original] = $file->uid; break; - case 'nid': - $replacements[$original] = $file->nid; - break; - // Essential file data case 'name': $replacements[$original] = $sanitize ? check_plain($file->filename) : $file->filename; @@ -264,7 +251,7 @@ function system_tokens($type, $tokens, array $data = array(), array $options = a break; case 'path': - $replacements[$original] = $sanitize ? filter_xss($file->filepath) : $file->filepath; + $replacements[$original] = $sanitize ? filter_xss($file->uri) : $file->uri; break; case 'mime': @@ -276,39 +263,27 @@ function system_tokens($type, $tokens, array $data = array(), array $options = a break; case 'url': - $replacements[$original] = url(file_create_url($file->filepath), $url_options); + $replacements[$original] = url(file_create_url($file->uri), $url_options); break; // These tokens are default variations on the chained tokens handled below. - case 'node': - if ($nid = $file->nid) { - $node = node_load($file->nid); - $replacements[$original] = $sanitize ? filter_xss($node->title) : $node->title; - } - break; - case 'timestamp': - $replacements[$original] = format_date($file->timestamp, 'medium', '', NULL, (isset($language) ? $language->language : NULL)); + $replacements[$original] = format_date($file->timestamp, 'medium', '', NULL, $langcode); break; case 'owner': $account = user_load($file->uid); - $replacements[$original] = $sanitize ? filter_xss($user->name) : $user->name; + $replacements[$original] = $sanitize ? filter_xss($account->name) : $account->name; break; } } - if ($node_tokens = token_find_with_prefix($tokens, 'node')) { - $node = node_load($file->nid); - $replacements += token_generate('node', $node_tokens, array('node' => $node), $language, $sanitize); - } - if ($date_tokens = token_find_with_prefix($tokens, 'timestamp')) { - $replacements += token_generate('date', $date_tokens, array('date' => $file->timestamp), $language, $sanitize); + $replacements += token_generate('date', $date_tokens, array('date' => $file->timestamp), $options); } if (($owner_tokens = token_find_with_prefix($tokens, 'owner')) && $account = user_load($file->uid)) { - $replacements += token_generate('user', $owner_tokens, array('user' => $account), $language, $sanitize); + $replacements += token_generate('user', $owner_tokens, array('user' => $account), $options); } } |