View source
<?php
define('ICONIZER_NO_THEMES', TRUE);
function iconizer_help($section = '') {
$output = '';
switch ($section) {
case "admin/help#iconizer":
$output = '<p>' . t("Adds icons next to links in Admin-section and well-know protocols and files") . '</p>';
break;
}
return $output;
}
function iconizer_perm() {
$perm = array();
$perm[] = 'display iconizer links';
$perm[] = 'manage iconizer settings';
return $perm;
}
function iconizer_menu($may_cache) {
$items = array();
if ($may_cache) {
$items[] = array(
'path' => 'admin/settings/iconizer',
'title' => t('Iconizer settings'),
'description' => t('Admin iconizer settings: Admin-links, files, protocols and themes'),
'callback' => 'drupal_get_form',
'callback arguments' => 'iconizer_admin',
'access' => user_access('manage iconizer settings'),
'type' => MENU_NORMAL_ITEM,
);
}
else {
_iconizer_add_css();
}
return $items;
}
function iconizer_admin() {
if (user_access('administer site configuration') && !defined('ICONIZER_NO_THEMES')) {
if (variable_get('iconizer_themes_enable', 0) !== 0 && !file_check_directory(file_create_path(variable_get('iconizer_themes_path', 'iconizer_themes')), FILE_CREATE_DIRECTORY)) {
$error = theme('error', t('The themes directory does not exist, or is not writable.'));
}
$form['themes'] = array(
'#type' => 'fieldset',
'#title' => t('Icon themes settings'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['themes']['iconizer_themes_enable'] = array(
'#type' => 'checkbox',
'#title' => t('Enable icons themes'),
'#default_value' => variable_get('iconizer_themes_enable', 0),
'#description' => t('Enable this feature to access and choose icons themes for \'Admin\', \'Files\' and \'Protocols\''),
);
$form['themes']['iconizer_themes_path'] = array(
'#type' => 'textfield',
'#title' => t('Themes path'),
'#default_value' => variable_get('iconizer_themes_path', ''),
'#size' => 45,
'#maxlength' => 255,
'#description' => t('Subdirectory in the directory "%dir" where iconizer themes be stored.', array(
'%dir' => variable_get('file_directory_path', 'files') . '/',
)) . $error,
);
}
$form['admin_icons'] = array(
'#type' => 'fieldset',
'#title' => t('Admin link icons'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['files_icons'] = array(
'#type' => 'fieldset',
'#title' => t('Files link icons'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['proto_icons'] = array(
'#type' => 'fieldset',
'#title' => t('Protocols link icons'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
if (user_access('manage iconizer settings')) {
$form['admin_icons']['iconizer_admin_icons'] = array(
'#type' => 'checkbox',
'#title' => t('Enable icons in Admin pages'),
'#default_value' => variable_get('iconizer_admin_icons', 1),
);
$form['files_icons']['iconizer_files_icons'] = array(
'#type' => 'checkbox',
'#title' => t('Enable icons for files links'),
'#default_value' => variable_get('iconizer_files_icons', 0),
);
$form['proto_icons']['iconizer_proto_icons'] = array(
'#type' => 'checkbox',
'#title' => t('Enable icons for protocols links'),
'#default_value' => variable_get('iconizer_proto_icons', 0),
);
}
if (user_access('choose iconizer themes')) {
if (variable_get('iconizer_themes_enable', 0) !== 0) {
$form['admin_icons']['iconizer_admin_icons_theme'] = array(
'#type' => 'select',
'#title' => t('Choose Admin icons theme'),
'#default_value' => variable_get('iconizer_admin_icons_theme', 'default'),
'#options' => _iconizer_get_themes('admin'),
'#description' => t('Theme for Admin links icons.'),
);
$form['files_icons']['iconizer_files_icons_theme'] = array(
'#type' => 'select',
'#title' => t('Choose Files icons theme'),
'#default_value' => variable_get('iconizer_files_icons_theme', 'default'),
'#options' => _iconizer_get_themes('files'),
'#description' => t('Theme for Files links icons.'),
);
$form['proto_icons']['iconizer_proto_icons_theme'] = array(
'#type' => 'select',
'#title' => t('Choose Protocols icons theme'),
'#default_value' => variable_get('iconizer_proto_icons_theme', 'default'),
'#options' => _iconizer_get_themes('files'),
'#description' => t('Theme for Protocols links icons.'),
);
}
else {
$error = theme('error', t('The themes have been disabled.'));
}
}
return system_settings_form($form);
}
function _iconizer_get_themes($part) {
$themes = array(
'default' => 'Default theme',
);
if (variable_get('iconizer_themes_enable', 0) !== 0) {
$themes['test'] = 'test theme';
}
return $themes;
}
function _iconizer_add_css() {
if (variable_get('iconizer_admin_icons', 1) == 1 && arg(0) == 'admin') {
drupal_add_css(_iconizer_admin_css(variable_get('iconizer_admin_icons_theme', 'default')), 'module', 'screen');
}
if (variable_get('iconizer_files_icons', 0) == 1) {
drupal_add_css(_iconizer_files_css(variable_get('iconizer_files_icons_theme', 'default')), 'module', 'screen');
}
if (variable_get('iconizer_proto_icons', 0) == 1) {
drupal_add_css(_iconizer_proto_css(variable_get('iconizer_proto_icons_theme', 'default')), 'module', 'screen');
}
}
function _iconizer_proto_css($theme) {
return _iconizer_get_theme_path($theme, 'proto') . '/proto_icons.css';
}
function _iconizer_files_css($theme) {
return _iconizer_get_theme_path($theme, 'files') . '/files_icons.css';
}
function _iconizer_admin_css($theme) {
return _iconizer_get_theme_path($theme, 'admin') . '/admin_icons.css';
}
function _iconizer_get_theme_path($theme, $part) {
$default = drupal_get_path('module', 'iconizer');
if ($theme == 'default') {
return $default;
}
elseif (variable_get('iconizer_themes_enable', 0) != 0 && variable_get('iconizer_' . $part . '_icons_theme', 0) != 0) {
return variable_get('iconizer_' . $part . '_icons_theme', '');
}
else {
return $default;
}
}