Projet

Général

Profil

Paste
Télécharger (4,54 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / languageicons / languageicons.module @ de6df2cc

1
<?php
2
/**
3
 * @file
4
 * Icons for language links.
5
 *
6
 * This is a spin off from the Internationalization (i18n) package.
7
 */
8

    
9
/**
10
 * Implements hook_theme().
11
 */
12
function languageicons_theme() {
13
  return array(
14
    'languageicons_icon' => array(
15
      'variables' => array('language' => NULL, 'title' => NULL),
16
    ),
17
    'languageicons_place' => array(
18
      'variables' => array('text' => NULL, 'icon' => NULL, 'separator' => ' '),
19
    ),
20
  );
21
}
22

    
23
/**
24
 * Implements hook_help().
25
 *
26
 * @todo The @handbook link needs to change to a module specific one.
27
 */
28
function languageicons_help($path, $arg) {
29
  switch ($path) {
30
    case 'admin/help#languageicons':
31
      $output = '<p>' . t('This module manages language icons for multilingual sites:') . '</p>';
32
      $output .= '<ul>';
33
      $output .= '<li>' . t('Automatically adds icons to language links.') . '</li>';
34
      $output .= '<li>' . t('Provides related theme functions.') . '</li>';
35
      $output .= '</ul>';
36
      $output .= '<p>' . t('For more information, please see <a href="@handbook">the online handbook section</a>.', array('@handbook' => 'http://drupal.org/node/133977')) . '</p>';
37
      return $output;
38
    case 'admin/config/regional/language/icons':
39
      $output = '<p>' . t('To enable multilingual support for specific content types go to <a href="@configure_content_types">configure content types</a>.', array('@configure_content_types' => url('admin/structure/types'))) . '</p>';
40
      return $output;
41
  }
42
}
43

    
44
/**
45
 * Implements hook_menu().
46
 */
47
function languageicons_menu() {
48
  $items['admin/config/regional/language/icons'] = array(
49
    'title' => 'Icons',
50
    'page callback' => 'drupal_get_form',
51
    'page arguments' => array('languageicons_admin_settings'),
52
    'weight' => 10,
53
    'type' => MENU_LOCAL_TASK,
54
    'access arguments' => array('administer languages'),
55
    'file' => 'languageicons.admin.inc',
56
  );
57
  return $items;
58
}
59

    
60
/**
61
 * Implements hook_language_switch_links_alter().
62
 *
63
 * Adds language icons to language switcher block links.
64
 *
65
 * @todo Figure out a way to either ignore node links or specifically target
66
 *   them here. See http://drupal.org/node/1005144 for more info.
67
 */
68
function languageicons_language_switch_links_alter(array &$links, $type, $path) {
69
  if (variable_get('languageicons_show_block', 1) || variable_get('languageicons_show_node', 1)) {
70
    foreach (array_keys($links) as $langcode) {
71
      if (!isset($links[$langcode]['language'])) {
72
        $lang_obj['language'] = $langcode;
73
        $links[$langcode]['language'] = (object) $lang_obj;
74
      }
75
      languageicons_link_add($links[$langcode]);
76
    }
77
  }
78
}
79

    
80
/**
81
 * Add language icon to link.
82
 *
83
 * The language icon may be a different language as the destination page, can be passed in 'language_icon'.
84
 */
85
function languageicons_link_add(&$link, $title = NULL) {
86
  $language = isset($link['language_icon']) ? $link['language_icon'] : $link['language'];
87
  $title = $title ? $title : $link['title'];
88
  $icon = theme('languageicons_icon', array(
89
    'language' => $language,
90
    'title' => check_plain($title),
91
  ));
92
  if ($icon) {
93
    $link['title'] = theme('languageicons_place', array(
94
      'text' => check_plain($link['title']),
95
      'icon' => $icon,
96
    ));
97
    $link['html'] = TRUE;
98
  }
99
}
100

    
101
/**
102
 * Theme language icon.
103
 *
104
 * This function can be overridden for no language icons.
105
 *
106
 * @seealso theme_image()
107
 */
108
function theme_languageicons_icon($variables) {
109
  $language = $variables['language'];
110
  $title    = $variables['title'];
111

    
112
  if ($path = variable_get('languageicons_path', drupal_get_path('module', 'languageicons') . '/flags/*.png')) {
113
    $title = $title ? $title : $language->native;
114
    // Build up $image for theme_image() consumption.
115
    $image = array(
116
      'path' => str_replace('*', $language->language, check_plain($path)),
117
      'alt' => $title,
118
      'title' => $title,
119
      'attributes' => array(
120
        'class' => array('language-icon'),
121
      ),
122
    );
123
    if ($size = check_plain(variable_get('languageicons_size', '16x12'))) {
124
      list($width, $height) = explode('x', $size);
125
      $image += array('width' => $width, 'height' => $height);
126
    }
127
    return theme('image', $image);
128
  }
129
}
130

    
131
/**
132
 * Theme language icon and text.
133
 *
134
 * @ingroup themeable
135
 */
136
function theme_languageicons_place($variables) {
137
  $text = $variables['text'];
138
  $icon = $variables['icon'];
139
  $separator = $variables['separator'];
140

    
141
  switch (variable_get('languageicons_placement', 'before')) {
142
    case 'after':
143
      return $text . $separator . $icon;
144
    case 'replace':
145
      return $icon;
146
    case 'before':
147
    default:
148
      return $icon . $separator . $text;
149
  }
150
}