You are here

function menu_icons_css_generate in Menu Icons 8

Same name and namespace in other branches
  1. 7.3 menu_icons.module \menu_icons_css_generate()

Build CSS based on menu IDs

Return value

A string with the CSS

2 calls to menu_icons_css_generate()
menu_icons_flush_caches in ./menu_icons.module
Implementation of hook_flush_caches().
menu_icons_form_submit in ./menu_icons.module
Process the submitted form
1 string reference to 'menu_icons_css_generate'
menu_icons_form_alter in ./menu_icons.module
Implementation of hook_form_alter().

File

./menu_icons.module, line 224
Module to associate icons with menu items

Code

function menu_icons_css_generate() {
  $result = db_query("SELECT mlid, options FROM {menu_links}");
  $pos = variable_get('menu_icons_position', 'left');
  while ($item = db_fetch_array($result)) {
    $options = unserialize($item['options']);
    if ($options['menu_icon']['enable'] && !empty($options['menu_icon']['path']) && file_exists($options['menu_icon']['path'])) {
      if (module_exists('imagecache')) {
        $preset = imagecache_preset_by_name($options['menu_icon']['imagecache_preset'] ? $options['menu_icon']['imagecache_preset'] : variable_get('menu_icons_imagecache_default', 'menu_icon'));
        $path = imagecache_create_path($preset['presetname'], $options['menu_icon']['path']);
        imagecache_build_derivative($preset['actions'], $options['menu_icon']['path'], $path);
        $options['menu_icon']['path'] = $path;
      }

      // Retrieve the image dimensions
      $info = image_get_info($options['menu_icon']['path']);

      // Support private filesystem
      if (strpos($options['menu_icon']['path'], menu_icons_directory_path()) === 0) {
        $image_url = file_create_url($options['menu_icon']['path']);
      }
      else {
        $image_url = base_path() . $options['menu_icon']['path'];
      }
      $css .= theme('menu_icons_css_item', $item['mlid'], $image_url, $info['width'], $pos);
    }
  }
  file_save_data($css, menu_icons_directory_path(FALSE) . '/menu_icons.css', FILE_EXISTS_REPLACE);
}