? .DS_Store
Index: menu_icons.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/menu_icons/menu_icons.module,v
retrieving revision 1.2.2.2
diff -u -p -r1.2.2.2 menu_icons.module
--- menu_icons.module	23 Jun 2009 06:22:58 -0000	1.2.2.2
+++ menu_icons.module	21 Jul 2009 05:47:49 -0000
@@ -9,19 +9,10 @@
  *
  */
 
-// TODO - provide option for linked, inline img tags, in addition to background CSS
-// TODO - implement blocks
-
 /**
  * Implementation of hook_menu().
  */
 function menu_icons_menu() {
-  $items['menu_icons/css'] = array(
-    'title' => 'Menu icons CSS',
-    'page callback' => 'menu_icons_css',
-    'access arguments' => array('access content'),
-    'type' => MENU_CALLBACK,
-  );
   $items['admin/settings/menu_icons'] = array(
     'title' => 'Menu Icon settings',
     'description' =>  'Associates icons with menu items',
@@ -73,6 +64,7 @@ function menu_icons_form_alter(&$form, $
 
     $form['#attributes']['enctype'] = 'multipart/form-data';
     $form['#submit'][] = 'menu_icons_form_submit';
+    $form['#submit'][] = '_menu_icons_css_generate';
   }
 }
 
@@ -82,9 +74,6 @@ function menu_icons_form_alter(&$form, $
  */
 function menu_icons_form_submit($form, &$form_state) {
 
-  // Clear the cached css
-  cache_clear_all('menu_icons', 'cache');
-
   // Get the global setings
   $file_validate_image_resolution = variable_get('menu_icons_file_validate_image_resolution', '45x45');
   $image_folder = variable_get('menu_icons_image_folder', 'menu_icons');
@@ -115,7 +104,7 @@ function menu_icons_form_submit($form, &
     file_copy($file, $filename, FILE_EXISTS_REPLACE);
     $path = $filename;
   }
-  
+
   $options = unserialize(db_result(db_query('SELECT options FROM {menu_links} WHERE mlid = %d', $form_state['values']['menu']['mlid'])));
   $options['menu_icon'] = array('enable' => $form_state['values']['use_icon_logo'], 'path' => $path);
   $options['attributes']['class'] = "menu_icon menu-". $form_state['values']['menu']['mlid'];
@@ -123,13 +112,6 @@ function menu_icons_form_submit($form, &
 }
 
 /**
- * Implementation of hook_init().
- */
-function menu_icons_init() {
-  drupal_set_html_head('<link type="text/css" rel="stylesheet" media="all" href="'. url('menu_icons/css') .'" />');
-}
-
-/**
  * Build the menu_icon's settings form
  *
  * @return a form array
@@ -167,54 +149,20 @@ function menu_icons_admin_settings() {
     ),
     '#required' => FALSE,
   );
-
-  // Clear the cached css
-  cache_clear_all('menu_icons', 'cache');
+  $form['#submit'][] = '_menu_icons_css_generate';
 
   return system_settings_form($form);
 }
 
-
-/**
- * Page callback for generated CSS file
- *
- */
-function menu_icons_css() {
-  drupal_set_header('Content-Type: text/css; charset=utf-8');
-  print _menu_icons_css_generate();
-}
-
 /**
- * Build CSS based on menu IDs
- *
- * @return A string with the CSS
+ * Implementation of hook_init().
  */
-function _menu_icons_css_generate() {
-
-  // Check if there's already stored data
-  if ($cache = cache_get('menu_icons')) {
-    return $cache->data;
-  }
-  else {
-    $result = db_query("SELECT mlid, options FROM {menu_links}");
-    $size = array_shift(split('x', variable_get('menu_icons_file_validate_image_resolution', '45x45')));
-    $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'])) {
-        $css .= theme('menu_icons_css_item', $item['mlid'], base_path() . $options['menu_icon']['path'], $size, $pos);
-      }
-    }
-    cache_set('menu_icons', $css);
-    return $css;
-  }
+function menu_icons_init() {
+  drupal_add_css(file_directory_path() .'/menu_icons.css');
 }
 
 /**
  * Implementation of hook_theme().
- *
  */
 function menu_icons_theme() {
   return array(
@@ -223,4 +171,32 @@ function menu_icons_theme() {
       'template' => 'menu_icons_css_item',
     ),
   );
-}
\ No newline at end of file
+}
+
+/**
+ * Build CSS based on menu IDs
+ */
+function _menu_icons_css_generate() {
+  $path = file_directory_path() .'/menu_icons.css';
+  $css = '';
+
+  // get the configuration settings
+  $size = array_shift(split('x', variable_get('menu_icons_file_validate_image_resolution', '45x45')));
+  $pos = variable_get('menu_icons_position', 'left');
+
+  // Get all stored menu_icon items from the db
+  $result = db_query("SELECT mlid, options FROM {menu_links}");
+
+  // Generate our CSS output
+  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'])) {
+      $css .= theme('menu_icons_css_item', $item['mlid'], base_path() . $options['menu_icon']['path'], $size, $pos);
+    }
+  }
+
+  // Try to write it to a file
+  if (!file_save_data($css, $path, FILE_EXISTS_REPLACE)) {
+    drupal_set_message(t('The file %file is not writable!', array('%file' => $path)), 'error');
+  }
+}
