- #20809: User-configurable, per-theme, optional favicons.
							parent
							
								
									753bc588d9
								
							
						
					
					
						commit
						6be2c61896
					
				| 
						 | 
					@ -216,7 +216,10 @@ function theme_get_settings($key = NULL) {
 | 
				
			||||||
    'mission'                       =>  '',
 | 
					    'mission'                       =>  '',
 | 
				
			||||||
    'default_logo'                  =>  1,
 | 
					    'default_logo'                  =>  1,
 | 
				
			||||||
    'logo_path'                     =>  '',
 | 
					    'logo_path'                     =>  '',
 | 
				
			||||||
 | 
					    'default_favicon'               =>  1,
 | 
				
			||||||
 | 
					    'favicon_path'                  =>  '',
 | 
				
			||||||
    'toggle_logo'                   =>  1,
 | 
					    'toggle_logo'                   =>  1,
 | 
				
			||||||
 | 
					    'toggle_favicon'                =>  1,
 | 
				
			||||||
    'toggle_name'                   =>  1,
 | 
					    'toggle_name'                   =>  1,
 | 
				
			||||||
    'toggle_search'                 =>  1,
 | 
					    'toggle_search'                 =>  1,
 | 
				
			||||||
    'toggle_slogan'                 =>  0,
 | 
					    'toggle_slogan'                 =>  0,
 | 
				
			||||||
| 
						 | 
					@ -289,6 +292,20 @@ function theme_get_setting($setting_name, $refresh = FALSE) {
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ($settings['toggle_favicon']) {
 | 
				
			||||||
 | 
					      if ($settings['default_favicon']) {
 | 
				
			||||||
 | 
					        if (file_exists($favicon = dirname($theme_object->filename) .'/favicon.ico')) {
 | 
				
			||||||
 | 
					          $settings['favicon'] = $favicon;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        else {
 | 
				
			||||||
 | 
					          $settings['favicon'] = 'misc/favicon.ico';
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      elseif ($settings['favicon_path']) {
 | 
				
			||||||
 | 
					        $settings['favicon'] = $settings['favicon_path'];
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    foreach (array('primary', 'secondary') as $type) {
 | 
					    foreach (array('primary', 'secondary') as $type) {
 | 
				
			||||||
      // Get the data to populate the textfields, if the variable is not an array .. try to parse the old-style link format.
 | 
					      // Get the data to populate the textfields, if the variable is not an array .. try to parse the old-style link format.
 | 
				
			||||||
      $value = $settings[$type . '_links'];
 | 
					      $value = $settings[$type . '_links'];
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
		 Before Width: | Height: | Size: 8.2 KiB After Width: | Height: | Size: 8.2 KiB  | 
| 
						 | 
					@ -633,6 +633,19 @@ function system_theme_settings($key = '') {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Check for a new uploaded favicon, and use that instead.
 | 
				
			||||||
 | 
					  if ($file = file_check_upload('favicon_upload')) {
 | 
				
			||||||
 | 
					    $parts = pathinfo($file->filename);
 | 
				
			||||||
 | 
					    $filename = ($key) ? str_replace('/', '_', $key) . '_favicon.' . $parts['extension'] : 'favicon.' . $parts['extension'];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ($file = file_save_upload('favicon_upload', $filename, 1)) {
 | 
				
			||||||
 | 
					      $settings['default_favicon'] = 0;
 | 
				
			||||||
 | 
					      $settings['favicon_path'] = $file->filepath;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      // Update the variable table with the new settings so that they take effect immediately.
 | 
				
			||||||
 | 
					      variable_set($var, $settings);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  $form = '';
 | 
					  $form = '';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -643,10 +656,20 @@ function system_theme_settings($key = '') {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    file_check_directory(variable_get('file_directory_path', 'files'), FILE_CREATE_DIRECTORY, 'file_directory_path');
 | 
					    file_check_directory(variable_get('file_directory_path', 'files'), FILE_CREATE_DIRECTORY, 'file_directory_path');
 | 
				
			||||||
    $group .= form_file(t('Upload logo image'), 'logo_upload', 40, t("If you don't have direct file access to the server, use this field to upload your logo."));
 | 
					    $group .= form_file(t('Upload logo image'), 'logo_upload', 40, t("If you don't have direct file access to the server, use this field to upload your logo."));
 | 
				
			||||||
    $group .= form_button(t('Upload'), 'fileop');
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    $form = form_group(t('Logo image settings'), $group);
 | 
					    $form .= form_group(t('Logo image settings'), $group);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Icon settings
 | 
				
			||||||
 | 
					  if ((!$key) || in_array('toggle_favicon', $features)) {
 | 
				
			||||||
 | 
					    $group = t('Your shortcut icon or \'favicon\' is displayed in the address bar and bookmarks of most browsers.');
 | 
				
			||||||
 | 
					    $group .= form_checkbox(t('Use the default shortcut icon.'), "$var][default_favicon", 1, $settings['default_favicon'], t('Check here if you want the theme to use the default shortcut icon.'));
 | 
				
			||||||
 | 
					    $group .= form_textfield(t('Path to custom icon'), "$var][favicon_path", $settings['favicon_path'], 50, 128, t('The path to the image file you would like to use as your custom shortcut icon.'));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    file_check_directory(variable_get('file_directory_path', 'files'), FILE_CREATE_DIRECTORY, 'file_directory_path');
 | 
				
			||||||
 | 
					    $group .= form_file(t('Upload icon image'), 'favicon_upload', 40, t("If you don't have direct file access to the server, use this field to upload your shortcut icon."));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    $form .= form_group(t('Shortcut icon settings'), $group);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // System wide only settings.
 | 
					  // System wide only settings.
 | 
				
			||||||
| 
						 | 
					@ -709,7 +732,8 @@ function system_theme_settings($key = '') {
 | 
				
			||||||
        'toggle_secondary_links' => t('Secondary links'),
 | 
					        'toggle_secondary_links' => t('Secondary links'),
 | 
				
			||||||
        'toggle_node_user_picture' => t('User pictures in posts'),
 | 
					        'toggle_node_user_picture' => t('User pictures in posts'),
 | 
				
			||||||
        'toggle_comment_user_picture' => t('User pictures in comments'),
 | 
					        'toggle_comment_user_picture' => t('User pictures in comments'),
 | 
				
			||||||
        'toggle_search' => t('Search box'));
 | 
					        'toggle_search' => t('Search box'),
 | 
				
			||||||
 | 
					        'toggle_favicon' => t('Shortcut icon'));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  foreach ($toggles as $name => $title) {
 | 
					  foreach ($toggles as $name => $title) {
 | 
				
			||||||
    if ((!$key) || in_array($name, $features)) {
 | 
					    if ((!$key) || in_array($name, $features)) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -633,6 +633,19 @@ function system_theme_settings($key = '') {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Check for a new uploaded favicon, and use that instead.
 | 
				
			||||||
 | 
					  if ($file = file_check_upload('favicon_upload')) {
 | 
				
			||||||
 | 
					    $parts = pathinfo($file->filename);
 | 
				
			||||||
 | 
					    $filename = ($key) ? str_replace('/', '_', $key) . '_favicon.' . $parts['extension'] : 'favicon.' . $parts['extension'];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ($file = file_save_upload('favicon_upload', $filename, 1)) {
 | 
				
			||||||
 | 
					      $settings['default_favicon'] = 0;
 | 
				
			||||||
 | 
					      $settings['favicon_path'] = $file->filepath;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      // Update the variable table with the new settings so that they take effect immediately.
 | 
				
			||||||
 | 
					      variable_set($var, $settings);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  $form = '';
 | 
					  $form = '';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -643,10 +656,20 @@ function system_theme_settings($key = '') {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    file_check_directory(variable_get('file_directory_path', 'files'), FILE_CREATE_DIRECTORY, 'file_directory_path');
 | 
					    file_check_directory(variable_get('file_directory_path', 'files'), FILE_CREATE_DIRECTORY, 'file_directory_path');
 | 
				
			||||||
    $group .= form_file(t('Upload logo image'), 'logo_upload', 40, t("If you don't have direct file access to the server, use this field to upload your logo."));
 | 
					    $group .= form_file(t('Upload logo image'), 'logo_upload', 40, t("If you don't have direct file access to the server, use this field to upload your logo."));
 | 
				
			||||||
    $group .= form_button(t('Upload'), 'fileop');
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    $form = form_group(t('Logo image settings'), $group);
 | 
					    $form .= form_group(t('Logo image settings'), $group);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Icon settings
 | 
				
			||||||
 | 
					  if ((!$key) || in_array('toggle_favicon', $features)) {
 | 
				
			||||||
 | 
					    $group = t('Your shortcut icon or \'favicon\' is displayed in the address bar and bookmarks of most browsers.');
 | 
				
			||||||
 | 
					    $group .= form_checkbox(t('Use the default shortcut icon.'), "$var][default_favicon", 1, $settings['default_favicon'], t('Check here if you want the theme to use the default shortcut icon.'));
 | 
				
			||||||
 | 
					    $group .= form_textfield(t('Path to custom icon'), "$var][favicon_path", $settings['favicon_path'], 50, 128, t('The path to the image file you would like to use as your custom shortcut icon.'));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    file_check_directory(variable_get('file_directory_path', 'files'), FILE_CREATE_DIRECTORY, 'file_directory_path');
 | 
				
			||||||
 | 
					    $group .= form_file(t('Upload icon image'), 'favicon_upload', 40, t("If you don't have direct file access to the server, use this field to upload your shortcut icon."));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    $form .= form_group(t('Shortcut icon settings'), $group);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // System wide only settings.
 | 
					  // System wide only settings.
 | 
				
			||||||
| 
						 | 
					@ -709,7 +732,8 @@ function system_theme_settings($key = '') {
 | 
				
			||||||
        'toggle_secondary_links' => t('Secondary links'),
 | 
					        'toggle_secondary_links' => t('Secondary links'),
 | 
				
			||||||
        'toggle_node_user_picture' => t('User pictures in posts'),
 | 
					        'toggle_node_user_picture' => t('User pictures in posts'),
 | 
				
			||||||
        'toggle_comment_user_picture' => t('User pictures in comments'),
 | 
					        'toggle_comment_user_picture' => t('User pictures in comments'),
 | 
				
			||||||
        'toggle_search' => t('Search box'));
 | 
					        'toggle_search' => t('Search box'),
 | 
				
			||||||
 | 
					        'toggle_favicon' => t('Shortcut icon'));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  foreach ($toggles as $name => $title) {
 | 
					  foreach ($toggles as $name => $title) {
 | 
				
			||||||
    if ((!$key) || in_array($name, $features)) {
 | 
					    if ((!$key) || in_array($name, $features)) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -9,6 +9,7 @@
 | 
				
			||||||
function chameleon_features() {
 | 
					function chameleon_features() {
 | 
				
			||||||
  return array(
 | 
					  return array(
 | 
				
			||||||
       'logo',
 | 
					       'logo',
 | 
				
			||||||
 | 
					       'toggle_favicon',
 | 
				
			||||||
       'toggle_name',
 | 
					       'toggle_name',
 | 
				
			||||||
       'toggle_slogan',
 | 
					       'toggle_slogan',
 | 
				
			||||||
       'toggle_primary_links',
 | 
					       'toggle_primary_links',
 | 
				
			||||||
| 
						 | 
					@ -18,6 +19,10 @@ function chameleon_features() {
 | 
				
			||||||
function chameleon_page($content) {
 | 
					function chameleon_page($content) {
 | 
				
			||||||
  $language = $GLOBALS['locale'];
 | 
					  $language = $GLOBALS['locale'];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (theme_get_setting('toggle_favicon')) {
 | 
				
			||||||
 | 
					    drupal_set_html_head('<link rel="shortcut icon" href="'. check_url(theme_get_setting('favicon')) .'" type="image/x-icon" />');
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  $title = drupal_get_title();
 | 
					  $title = drupal_get_title();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  $output  = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n";
 | 
					  $output  = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n";
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -93,6 +93,7 @@ function _phptemplate_default_variables($hook, $variables) {
 | 
				
			||||||
function phptemplate_features() {
 | 
					function phptemplate_features() {
 | 
				
			||||||
  return array(
 | 
					  return array(
 | 
				
			||||||
       'logo',
 | 
					       'logo',
 | 
				
			||||||
 | 
					       'toggle_favicon',
 | 
				
			||||||
       'toggle_name',
 | 
					       'toggle_name',
 | 
				
			||||||
       'toggle_search',
 | 
					       'toggle_search',
 | 
				
			||||||
       'toggle_slogan',
 | 
					       'toggle_slogan',
 | 
				
			||||||
| 
						 | 
					@ -110,15 +111,16 @@ function phptemplate_features() {
 | 
				
			||||||
function phptemplate_page($content) {
 | 
					function phptemplate_page($content) {
 | 
				
			||||||
  /* Set title and breadcrumb to declared values */
 | 
					  /* Set title and breadcrumb to declared values */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (file_exists(path_to_theme() . '/favicon.ico')) {
 | 
					 | 
				
			||||||
    drupal_set_html_head("<link rel=\"shortcut icon\" href=\"" . path_to_theme() . "/favicon.ico\" />\n");
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  if ($_GET['q'] == variable_get('site_frontpage', 'node')) {
 | 
					  if ($_GET['q'] == variable_get('site_frontpage', 'node')) {
 | 
				
			||||||
    $mission = theme_get_setting('mission');
 | 
					    $mission = theme_get_setting('mission');
 | 
				
			||||||
    $frontpage = true;
 | 
					    $frontpage = true;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /* Add favicon */
 | 
				
			||||||
 | 
					  if (theme_get_setting('toggle_favicon')) {
 | 
				
			||||||
 | 
					    drupal_set_html_head('<link rel="shortcut icon" href="'. check_url(theme_get_setting('favicon')) .'" type="image/x-icon" />');
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
  * Populate sidebars.
 | 
					  * Populate sidebars.
 | 
				
			||||||
  */
 | 
					  */
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue