touch_icons.module in Touch Icons 7.2
Same filename and directory in other branches
Adds a fieldset to theme settings form which allows site administrators to specify Apple Touch icons for Drupal websites. The Touch icon settings behave in a similar manner to the Site Logo and Favicon settings provided by Drupal core.
Also provides a simple means for theme developers to provide default Touch icons with their theme.
@todo implement hook_help() ? @todo hook_update() if needs be
@todo IMPORTANT figure out new variable naming scheme!!!!
@todo refactor/deprecate _touch_icons_get_theme_settings_key
@todo private helper function to get icon URLs, like in 6.x-1.x
File
touch_icons.moduleView source
<?php
/**
* @file
*
* Adds a fieldset to theme settings form which allows site administrators to
* specify Apple Touch icons for Drupal websites. The Touch icon settings behave
* in a similar manner to the Site Logo and Favicon settings provided by Drupal
* core.
*
* Also provides a simple means for theme developers to provide default Touch
* icons with their theme.
*
* @todo implement hook_help() ?
* @todo hook_update() if needs be
*
* @todo IMPORTANT figure out new variable naming scheme!!!!
*
* @todo refactor/deprecate _touch_icons_get_theme_settings_key
* - http://drupal.org/node/1762532
*
* @todo private helper function to get icon URLs, like in 6.x-1.x
*/
/**
* Sizes supported touch icons
*
* @return array of icon sizes, in pixels
*/
function _touch_icons_supported_icon_sizes() {
return array(
57,
// iPhone
72,
// iPad
114,
//iPhone Retina
144,
);
}
/**
* Implements hook_hook_info().
*/
function touch_icons_hook_info() {
$hooks['form_system_theme_settings_alter'] = array(
'group' => 'admin',
);
return $hooks;
}
/**
* Implement MODULENAME_preprocess_html().
*
* @todo review http://api.drupal.org/api/function/drupal_add_html_head/7
* shall we specify a $key as second argument?
*/
function touch_icons_preprocess_html(&$vars) {
// If no key is given, use the current theme if we can determine it.
$theme = !empty($GLOBALS['theme_key']) ? $GLOBALS['theme_key'] : '';
if ($theme) {
$themes = list_themes();
$theme_object = $themes[$theme];
}
// build apple-touch-icon URL
$url_plain = '';
if (theme_get_setting('toggle_touch_icon_plain')) {
// include icon link
if (theme_get_setting('default_touch_icon_plain')) {
// use default icon from theme or module
if (file_exists($touch_icon = dirname($theme_object->filename) . '/apple-touch-icon.png')) {
// theme provides a default icon
$url_plain = file_create_url($touch_icon);
}
else {
// fallback to module-provided default icon
$url_plain = file_create_url(drupal_get_path('module', 'touch_icons') . '/apple-touch-icon.png');
}
}
elseif (theme_get_setting('touch_icon_path_plain')) {
// custom icon
$url_plain = file_create_url(theme_get_setting('touch_icon_path_plain'));
}
}
// build apple-touch-icon URL
$url_precomp = '';
if (theme_get_setting('toggle_touch_icon_precomp')) {
// include icon link
if (theme_get_setting('default_touch_icon_precomp')) {
// use default icon from theme or module
if (file_exists($touch_icon = dirname($theme_object->filename) . '/apple-touch-icon-precomposed.png')) {
// theme provides a default icon
$url_precomp = file_create_url($touch_icon);
}
else {
// fallback to module-provided default icon
$url_precomp = file_create_url(drupal_get_path('module', 'touch_icons') . '/apple-touch-icon-precomposed.png');
}
}
elseif (theme_get_setting('touch_icon_path_precomp')) {
// custom icon
$url_precomp = file_create_url(theme_get_setting('touch_icon_path_precomp'));
}
}
// output links
if (check_url($url_plain)) {
// no output if $url_plain = ''
drupal_add_html_head_link(array(
'rel' => 'apple-touch-icon',
'href' => $url_plain,
'type' => file_get_mimetype($url_plain),
));
}
if (check_url($url_precomp)) {
// no output if $url_precomp = ''
drupal_add_html_head_link(array(
'rel' => 'apple-touch-icon-precomposed',
'href' => $url_precomp,
'type' => file_get_mimetype($url_precomp),
));
}
}
Functions
Name![]() |
Description |
---|---|
touch_icons_hook_info | Implements hook_hook_info(). |
touch_icons_preprocess_html | Implement MODULENAME_preprocess_html(). |
_touch_icons_supported_icon_sizes | Sizes supported touch icons |