/[drupal]/contributions/modules/i18n/languageicons/languageicons.module
ViewVC logotype

Contents of /contributions/modules/i18n/languageicons/languageicons.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.3 - (show annotations) (download) (as text)
Fri Feb 15 22:51:42 2008 UTC (21 months, 1 week ago) by jareyero
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-6--1
Changes since 1.2: +19 -9 lines
File MIME type: text/x-php
Updating for Drupal 6.0
1 <?php
2 // $Id: languageicons.module,v 1.2 2007/12/04 20:46:43 jareyero Exp $
3
4 /**
5 * @file
6 * Language icons
7 *
8 * Internationalization (i18n) package
9 *
10 * @author Jose A. Reyero, 2007
11 *
12 */
13
14 /**
15 * Implementation of hook_theme()
16 */
17 function languageicons_theme() {
18 return array(
19 'languageicons_icon' => array(
20 'arguments' => array('language' => NULL, 'title' => NULL),
21 ),
22 'languageicons_place' => array(
23 'arguments' => array('text' => NULL, 'icon' => NULL, 'separator' => ' '),
24 ),
25 );
26 }
27
28 /**
29 * Implementation of hook_help().
30 */
31 function languageicons_help($section = 'admin/help#languageicons' ) {
32 switch ($section) {
33 case 'admin/help#languageicons' :
34 $output = '<p>'.t('This module manages language icons for multilingual sites:').'</p>';
35 $output .= '<ul>';
36 $output .= '<li>'.t('Automatically adds icons to language links').'</li>';
37 $output .= '<li>'.t('Provides related theme functions').'</li>';
38 $output .= '</ul>';
39 $output .= '<p>'. t('For more information please read the <a href="@i18n">on-line help pages</a>.', array('@i18n' =>'http://drupal.org/node/31631')) .'</p>';
40 return $output;
41 case 'admin/settings/languageicons':
42 $output .= '<p>'.t('To enable multilingual support for specific content types go to !configure_content_types.', array('!configure_content_types' => l(t('configure content types'), 'admin/content/types'), )).'</p>';
43 return $output;
44 }
45 }
46
47 /**
48 * Implementation of hook_menu().
49 */
50 function languageicons_menu() {
51 $items['admin/settings/language/configure/options'] = array(
52 'title' => 'Configure',
53 'weight' => 10,
54 'type' => MENU_DEFAULT_LOCAL_TASK,
55 );
56
57 $items['admin/settings/language/configure/icons'] = array(
58 'title' => 'Icons',
59 'page callback' => 'drupal_get_form',
60 'page arguments' => array('languageicons_admin_settings'),
61 'weight' => 10,
62 'type' => MENU_LOCAL_TASK,
63 );
64 return $items;
65 }
66
67 /**
68 * Implementation of hook_alter_translation_link().
69 *
70 * Adds language icons to normal translation links.
71 */
72 function languageicons_translation_link_alter(&$links, $path) {
73 foreach (array_keys($links) as $langcode) {
74 languageicons_link_add($links[$langcode]);
75 }
76 }
77
78 /**
79 * Implementation of hook_link_alter().
80 *
81 * Adds language icons to node links.
82 */
83 function languageicons_link_alter(&$links, $node) {
84 if ($node->tnid && $translations = module_invoke('translation', 'node_get_translations', $node->tnid)) {
85 $languages = language_list();
86 foreach ($translations as $langcode => $translation) {
87 $index = 'node_translation_'.$langcode;
88 if (!empty($links[$index])) {
89 languageicons_link_add($links[$index]);
90 }
91 }
92 }
93 }
94
95 /**
96 * Add language icon to link
97 *
98 * The language icon may be a different language as the destination page, can be passed in 'language_icon'
99 */
100 function languageicons_link_add(&$link, $title = NULL) {
101 $language = isset($link['language_icon']) ? $link['language_icon'] : $link['language'];
102 $title = $title ? $title : $link['title'];
103 if ($icon = theme('languageicons_icon', $language, $title)) {
104 $link['title'] = theme('languageicons_place', $link['title'], $icon);
105 $link['html'] = TRUE;
106 }
107 }
108
109 /**
110 * Form builder function.
111 *
112 */
113 function languageicons_admin_settings() {
114
115 $form['languageicons_placement'] = array(
116 '#type' => 'radios',
117 '#title' => t('Icon placement'),
118 '#options' => array('before' => t('Before'), 'after' => t('After'), 'replace' => t('Replace')),
119 '#default_value' => variable_get('languageicons_placement', 'before'),
120 '#description' => t('Where to display the icon, relative to the link title.'),
121 );
122 $form['i18n_icon_path'] = array(
123 '#type' => 'textfield',
124 '#title' => t('Icons file path'),
125 '#default_value' => variable_get('i18n_icon_path', drupal_get_path('module', 'i18n').'/flags/*.png'),
126 '#size' => 70,
127 '#maxlength' => 180,
128 '#description' => t('Path for language icons, relative to Drupal installation. \'*\' is a placeholder for language code.'),
129 );
130 $form['i18n_icon_size'] = array(
131 '#type' => 'textfield',
132 '#title' => t('Image size'),
133 '#default_value' => variable_get('i18n_icon_size', '16x12'),
134 '#size' => 10,
135 '#maxlength' => 10,
136 '#description' => t('Image size for language icons, in the form "width x height".'),
137 );
138
139 return system_settings_form($form);
140 }
141
142 /**
143 * Theme language icon
144 *
145 * This function can be overridden for no language icons
146 */
147 function theme_languageicons_icon($language, $title = NULL){
148 if ($path = variable_get('i18n_icon_path', drupal_get_path('module', 'i18n').'/flags/*.png')) {
149 $src = base_path().str_replace('*', $language->language, $path);
150 $title = $title ? $title : $language->native;
151 $attribs = array('class' => 'language-icon', 'alt' => $title);
152 if ($size = variable_get('i18n_icon_size', '16x12')) {
153 list($width, $height) = explode('x', $size);
154 $attribs += array('width' => $width, 'height' => $height);
155 }
156 return "<img src=\"$src\" ".drupal_attributes($attribs)." />";
157 }
158 }
159
160 /**
161 * Theme language icon and text
162 */
163 function theme_languageicons_place($text, $icon, $separator = ' ') {
164 switch(variable_get('languageicons_placement', 'before')) {
165 case 'after':
166 return $text . $separator . $icon;
167 case 'replace':
168 return $icon;
169 case 'before':
170 default:
171 return $icon . $separator . $text;
172 }
173 }

  ViewVC Help
Powered by ViewVC 1.1.2