From c71bfded3dea1754633f29ac8e81fb3ab46b766a Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Wed, 4 Aug 2004 20:40:01 +0000 Subject: - Patch #9657: more intelligent theme() function. Hopefully, Adrian will be able to use this patch too. --- includes/tablesort.inc | 2 +- includes/theme.inc | 23 +++++++++++++++++------ modules/aggregator.module | 4 +++- modules/aggregator/aggregator.module | 4 +++- modules/forum.module | 4 ++-- modules/forum/forum.module | 4 ++-- modules/system.module | 2 +- modules/system/system.module | 2 +- modules/user.module | 5 +++-- modules/user/user.module | 5 +++-- 10 files changed, 36 insertions(+), 19 deletions(-) diff --git a/includes/tablesort.inc b/includes/tablesort.inc index e80eb544f..56d805e1b 100644 --- a/includes/tablesort.inc +++ b/includes/tablesort.inc @@ -77,8 +77,8 @@ function tablesort_header($cell, $header, $ts) { if ($cell['data'] == $ts['name']) { $ts['sort'] = (($ts['sort'] == 'asc') ? 'desc' : 'asc'); $cell['class'] = 'active'; - $image = ' '. t('sort icon') .''; $title = ($ts['sort'] == 'asc' ? t('sort ascending') : t('sort descending')); + $image = ' '. theme('image', 'misc/arrow-'. $ts['sort'] .'.png', t('sort icon'), $title); } else { // If the user clicks a different header, we want to sort ascending initially. diff --git a/includes/theme.inc b/includes/theme.inc index c43b45df6..60f9dfe43 100644 --- a/includes/theme.inc +++ b/includes/theme.inc @@ -235,13 +235,22 @@ function theme_links($links, $delimiter = ' | ') { /** * Return a themed image. * - * @param $name - * The name of the image file. + * @param $path + * The path of the image file. + * @param $alt + * The alternative text for text-based browsers. + * @param $title + * The title text is displayed when the image is hovered in some popular browsers. + * @param $attr + * Attributes placed in the img tag. + * This parameter overrides the default auto-detection of width and height. * @return - * The pathname of the themed image. + * A string containing the image tag. */ -function theme_image($name) { - return 'misc/'. $name; +function theme_image($path, $alt = NULL, $title = NULL, $attr = NULL) { + if (isset($attr) || (file_exists($path) && (list($width, $height, $type, $attr) = getimagesize($path)))) { + return "\"$alt\""; + } } /** @@ -511,7 +520,9 @@ function theme_error($message) { * Return code that emits an XML icon. */ function theme_xml_icon($url) { - return '
'. t('XML feed') .'
'; + if ($image = theme('image', 'misc/xml.png', t('XML feed'), t('XML feed'))) { + return '
'. $image. '
'; + } } /** diff --git a/modules/aggregator.module b/modules/aggregator.module index 694568ad2..903535461 100644 --- a/modules/aggregator.module +++ b/modules/aggregator.module @@ -1039,7 +1039,9 @@ function theme_aggregator_block_item($item, $feed = 0) { global $user; if ($user->uid && module_exist('blog') && user_access('edit own blog')) { - $output .= '
'. l(''. t('blog it') .'', 'node/add/blog', array('title' => t('Comment on this news item in your personal blog.'), 'class' => 'blog-it'), "iid=$item->iid") .'
'; + if ($image = theme('misc/blog.png', t('blog it'), t('blog it'))) { + $output .= '
'. l($image, 'node/add/blog', array('title' => t('Comment on this news item in your personal blog.'), 'class' => 'blog-it'), "iid=$item->iid") .'
'; + } } // external link diff --git a/modules/aggregator/aggregator.module b/modules/aggregator/aggregator.module index 694568ad2..903535461 100644 --- a/modules/aggregator/aggregator.module +++ b/modules/aggregator/aggregator.module @@ -1039,7 +1039,9 @@ function theme_aggregator_block_item($item, $feed = 0) { global $user; if ($user->uid && module_exist('blog') && user_access('edit own blog')) { - $output .= '
'. l(''. t('blog it') .'', 'node/add/blog', array('title' => t('Comment on this news item in your personal blog.'), 'class' => 'blog-it'), "iid=$item->iid") .'
'; + if ($image = theme('misc/blog.png', t('blog it'), t('blog it'))) { + $output .= '
'. l($image, 'node/add/blog', array('title' => t('Comment on this news item in your personal blog.'), 'class' => 'blog-it'), "iid=$item->iid") .'
'; + } } // external link diff --git a/modules/forum.module b/modules/forum.module index aaad68486..4d645cf02 100644 --- a/modules/forum.module +++ b/modules/forum.module @@ -705,9 +705,9 @@ function _forum_icon($new_posts, $num_posts = 0, $comment_mode = 0, $sticky = 0) } // default - $file = $base_path ."/forum-$icon.png"; + $file = "misc/forum-$icon.png"; - $output = "\"\""; + $output = theme('image', $file); } else { $output = ' '; diff --git a/modules/forum/forum.module b/modules/forum/forum.module index aaad68486..4d645cf02 100644 --- a/modules/forum/forum.module +++ b/modules/forum/forum.module @@ -705,9 +705,9 @@ function _forum_icon($new_posts, $num_posts = 0, $comment_mode = 0, $sticky = 0) } // default - $file = $base_path ."/forum-$icon.png"; + $file = "misc/forum-$icon.png"; - $output = "\"\""; + $output = theme('image', $file); } else { $output = ' '; diff --git a/modules/system.module b/modules/system.module index 9ea7daac2..170fd8090 100644 --- a/modules/system.module +++ b/modules/system.module @@ -233,7 +233,7 @@ function system_listing($type) { ksort($files); if ($type == 'module') { - $required = array('modules/admin.module', 'modules/filter.module', 'modules/system.module', 'modules/user.module', 'modules/watchdog.module'); + $required = array('modules/admin.module', 'modules/block.module', 'modules/filter.module', 'modules/system.module', 'modules/user.module', 'modules/watchdog.module'); // the throttle mechanism requires additional modules always be enabled $throttle_required = array_merge($required, array('modules/statistics.module', 'modules/throttle.module')); diff --git a/modules/system/system.module b/modules/system/system.module index 9ea7daac2..170fd8090 100644 --- a/modules/system/system.module +++ b/modules/system/system.module @@ -233,7 +233,7 @@ function system_listing($type) { ksort($files); if ($type == 'module') { - $required = array('modules/admin.module', 'modules/filter.module', 'modules/system.module', 'modules/user.module', 'modules/watchdog.module'); + $required = array('modules/admin.module', 'modules/block.module', 'modules/filter.module', 'modules/system.module', 'modules/user.module', 'modules/watchdog.module'); // the throttle mechanism requires additional modules always be enabled $throttle_required = array_merge($required, array('modules/statistics.module', 'modules/throttle.module')); diff --git a/modules/user.module b/modules/user.module index 9c9b0883c..42a5c395c 100644 --- a/modules/user.module +++ b/modules/user.module @@ -567,7 +567,8 @@ function theme_user_picture($account) { } if ($picture) { - $picture = "\"" $account->name ? $account->name : t(variable_get('anonymous', 'Anonymous')))) . '" />'; + $alt = t('%user\'s picture', array('%user' => $account->name ? $account->name : t(variable_get('anonymous', 'Anonymous')))); + $picture = theme('image', $picture, $alt, $alt); if ($account->uid) { $picture = l($picture, "user/$account->uid", array('title' => t('View user profile.'))); } @@ -1019,7 +1020,7 @@ function user_edit_form($uid, $edit) { if (variable_get('user_pictures', 0)) { $group = ''; if (file_exists($edit['picture'])) { - $group .= ''; + $group .= theme('image', file_create_url($edit['picture'])); } $group .= form_file(t('Upload picture'), 'picture', 48, t('Your virtual face or picture. Maximum dimensions are %dimensions and the maximum size is %size kB.', array('%dimensions' => variable_get('user_picture_dimensions', '85x85'), '%size' => variable_get('user_picture_file_size', '30'))) .' '. variable_get('user_picture_guidelines', '')); $data[] = array('title' => t('Picture'), 'data' => $group, 'weight' => 1); diff --git a/modules/user/user.module b/modules/user/user.module index 9c9b0883c..42a5c395c 100644 --- a/modules/user/user.module +++ b/modules/user/user.module @@ -567,7 +567,8 @@ function theme_user_picture($account) { } if ($picture) { - $picture = "\"" $account->name ? $account->name : t(variable_get('anonymous', 'Anonymous')))) . '" />'; + $alt = t('%user\'s picture', array('%user' => $account->name ? $account->name : t(variable_get('anonymous', 'Anonymous')))); + $picture = theme('image', $picture, $alt, $alt); if ($account->uid) { $picture = l($picture, "user/$account->uid", array('title' => t('View user profile.'))); } @@ -1019,7 +1020,7 @@ function user_edit_form($uid, $edit) { if (variable_get('user_pictures', 0)) { $group = ''; if (file_exists($edit['picture'])) { - $group .= ''; + $group .= theme('image', file_create_url($edit['picture'])); } $group .= form_file(t('Upload picture'), 'picture', 48, t('Your virtual face or picture. Maximum dimensions are %dimensions and the maximum size is %size kB.', array('%dimensions' => variable_get('user_picture_dimensions', '85x85'), '%size' => variable_get('user_picture_file_size', '30'))) .' '. variable_get('user_picture_guidelines', '')); $data[] = array('title' => t('Picture'), 'data' => $group, 'weight' => 1); -- cgit v1.2.3