function menu_icons_css_generate in Menu Icons 7.3
Same name and namespace in other branches
- 8 menu_icons.module \menu_icons_css_generate()
Build CSS based on menu IDs
Return value
A string with the CSS
3 calls to menu_icons_css_generate()
- menu_icons_flush_caches in ./
menu_icons.module - Implements hook_flush_caches().
- menu_icons_form_submit in ./
menu_icons.module - Process the submitted form
- menu_icons_node_save in ./
menu_icons.module - Helper for hook_node_insert() and hook_node_update().
1 string reference to 'menu_icons_css_generate'
- menu_icons_form_alter in ./
menu_icons.module - Implements hook_form_alter().
File
- ./
menu_icons.module, line 489 - Module to associate icons with menu items
Code
function menu_icons_css_generate() {
$css = "";
$result = db_query("SELECT mlid, options FROM {menu_links}");
$pos = variable_get('menu_icons_position', 'left');
$absolute = variable_get('menu_icons_absolute_links', FALSE);
foreach ($result as $item) {
$options = unserialize($item->options);
if (isset($options['menu_icon']) && $options['menu_icon']['enable'] && !empty($options['menu_icon']['path']) && file_exists($options['menu_icon']['path'])) {
$image_path = $options['menu_icon']['path'];
$image_style = isset($options['menu_icon']['image_style']) && !empty($options['menu_icon']['image_style']) ? $options['menu_icon']['image_style'] : NULL;
if ($image_style) {
$source_uri = $image_path;
$image_path = image_style_path($image_style, $source_uri);
if (!file_exists($image_path)) {
image_style_create_derivative(image_style_load($image_style), $source_uri, $image_path);
}
}
// Retrieve the image dimensions
$info = image_get_info($image_path);
if ($absolute) {
$image_url = file_create_url($image_path);
}
else {
$wrapper = file_stream_wrapper_get_instance_by_scheme(file_uri_scheme($image_path));
$image_url = '/' . $wrapper
->getDirectoryPath() . '/' . file_uri_target($image_path);
}
$size = $pos == 'right' || $pos == 'left' ? $info['width'] : $info['height'];
// Support private filesystem
$css .= theme('menu_icons_css_item', array(
'mlid' => $item->mlid,
'path' => $image_url,
'size' => $size,
'height' => $info['height'],
'pos' => $pos,
'source' => $source_uri,
));
}
}
$csspath = 'public://css';
if (!empty($css)) {
file_prepare_directory($csspath, FILE_CREATE_DIRECTORY);
file_unmanaged_delete($csspath . '/menu_icons.css');
file_unmanaged_save_data($css, $csspath . '/menu_icons.css', FILE_EXISTS_REPLACE);
}
else {
file_unmanaged_delete($csspath . '/menu_icons.css');
}
}