You are here

iconizer.module in Iconizer 5

Same filename and directory in other branches
  1. 6 iconizer.module
  2. 7 iconizer.module

File

iconizer.module
View source
<?php

/**
* Iconizer module: adds icons before links in Admin section.
* @author: thePanz ( thePanz@gmail.com )
*/
define('ICONIZER_NO_THEMES', TRUE);

/**
* Display help and module information
* @param section which section of the site we're displaying help
* @return help text for section
*/
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;
}

/**
* Valid permissions for this module
* @return array An array of valid permissions for the onthisdate module
*/
function iconizer_perm() {
  $perm = array();
  $perm[] = 'display iconizer links';
  $perm[] = 'manage iconizer settings';

  //$perm[] = 'choose iconizer themes'
  return $perm;
}

/**
* Menu hook
*/
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, choose iconizer themes '),
      'access' => user_access('manage iconizer settings'),
      'type' => MENU_NORMAL_ITEM,
    );
  }
  else {
    _iconizer_add_css();
  }
  return $items;
}

/**
* Admin hook
*/
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,
    );
  }

  // Creating Fieldsets
  // Admin-section
  $form['admin_icons'] = array(
    '#type' => 'fieldset',
    '#title' => t('Admin link icons'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );

  // Files icons
  $form['files_icons'] = array(
    '#type' => 'fieldset',
    '#title' => t('Files link icons'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );

  // Protocols icons
  $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.'));

      //$form = array();
    }
  }
  return system_settings_form($form);
}

/**
* Retrive themes for icons
*/
function _iconizer_get_themes($part) {

  // parts in "admin", "protocols" or "files"
  $themes = array(
    'default' => 'Default theme',
  );
  if (variable_get('iconizer_themes_enable', 0) !== 0) {
    $themes['test'] = 'test theme';

    // scan variable_get('iconizer_themes_path') for other themes
  }
  return $themes;
}

/**
* Add CSS function
*/
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;
  }
}

Functions

Namesort descending Description
iconizer_admin Admin hook
iconizer_help Display help and module information
iconizer_menu Menu hook
iconizer_perm Valid permissions for this module
_iconizer_add_css Add CSS function
_iconizer_admin_css
_iconizer_files_css
_iconizer_get_themes Retrive themes for icons
_iconizer_get_theme_path
_iconizer_proto_css

Constants

Namesort descending Description
ICONIZER_NO_THEMES Iconizer module: adds icons before links in Admin section. @author: thePanz ( thePanz@gmail.com )