| 1 |
<?php
|
| 2 |
// $Id: languageicons.module,v 1.4 2009/02/02 20:10:33 freso Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Icons for language links.
|
| 7 |
*
|
| 8 |
* This is a spin off from the Internationalization (i18n) package.
|
| 9 |
*
|
| 10 |
* @author Jose A. Reyero, 2007
|
| 11 |
*/
|
| 12 |
|
| 13 |
/**
|
| 14 |
* Implementation of hook_theme().
|
| 15 |
*/
|
| 16 |
function languageicons_theme() {
|
| 17 |
return array(
|
| 18 |
'languageicons_icon' => array(
|
| 19 |
'arguments' => array('language' => NULL, 'title' => NULL),
|
| 20 |
),
|
| 21 |
'languageicons_place' => array(
|
| 22 |
'arguments' => array('text' => NULL, 'icon' => NULL, 'separator' => ' '),
|
| 23 |
),
|
| 24 |
);
|
| 25 |
}
|
| 26 |
|
| 27 |
/**
|
| 28 |
* Implementation of hook_help().
|
| 29 |
*/
|
| 30 |
function languageicons_help($path, $arg) {
|
| 31 |
switch ($path) {
|
| 32 |
case 'admin/help#languageicons' :
|
| 33 |
$output = '<p>'. t('This module manages language icons for multilingual sites:') .'</p>';
|
| 34 |
$output .= '<ul>';
|
| 35 |
$output .= '<li>'. t('Automatically adds icons to language links') .'</li>';
|
| 36 |
$output .= '<li>'. t('Provides related theme functions') .'</li>';
|
| 37 |
$output .= '</ul>';
|
| 38 |
$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>';
|
| 39 |
return $output;
|
| 40 |
case 'admin/settings/languageicons':
|
| 41 |
$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>';
|
| 42 |
return $output;
|
| 43 |
}
|
| 44 |
}
|
| 45 |
|
| 46 |
/**
|
| 47 |
* Implementation of hook_menu().
|
| 48 |
*/
|
| 49 |
function languageicons_menu() {
|
| 50 |
$items['admin/settings/language/icons'] = array(
|
| 51 |
'title' => 'Icons',
|
| 52 |
'page callback' => 'drupal_get_form',
|
| 53 |
'page arguments' => array('languageicons_admin_settings'),
|
| 54 |
'weight' => 10,
|
| 55 |
'type' => MENU_LOCAL_TASK,
|
| 56 |
'access arguments' => array('administer languages'),
|
| 57 |
'file' => 'languageicons.admin.inc',
|
| 58 |
);
|
| 59 |
return $items;
|
| 60 |
}
|
| 61 |
|
| 62 |
/**
|
| 63 |
* Implementation of hook_alter_translation_link().
|
| 64 |
*
|
| 65 |
* Adds language icons to normal translation links.
|
| 66 |
*/
|
| 67 |
function languageicons_translation_link_alter(&$links, $path) {
|
| 68 |
if (variable_get('languageicons_show_block', 1)) {
|
| 69 |
foreach (array_keys($links) as $langcode) {
|
| 70 |
languageicons_link_add($links[$langcode]);
|
| 71 |
}
|
| 72 |
}
|
| 73 |
}
|
| 74 |
|
| 75 |
/**
|
| 76 |
* Implementation of hook_link_alter().
|
| 77 |
*
|
| 78 |
* Adds language icons to node links.
|
| 79 |
*/
|
| 80 |
function languageicons_link_alter(&$links, $node) {
|
| 81 |
if (variable_get('languageicons_show_node', 1) && (!empty($node->tnid)) && $translations = module_invoke('translation', 'node_get_translations', $node->tnid)) {
|
| 82 |
$languages = language_list();
|
| 83 |
foreach ($translations as $langcode => $translation) {
|
| 84 |
$index = 'node_translation_'. $langcode;
|
| 85 |
if (!empty($links[$index])) {
|
| 86 |
languageicons_link_add($links[$index]);
|
| 87 |
}
|
| 88 |
}
|
| 89 |
}
|
| 90 |
}
|
| 91 |
|
| 92 |
/**
|
| 93 |
* Add language icon to link.
|
| 94 |
*
|
| 95 |
* The language icon may be a different language as the destination page, can be passed in 'language_icon'.
|
| 96 |
*/
|
| 97 |
function languageicons_link_add(&$link, $title = NULL) {
|
| 98 |
$language = isset($link['language_icon']) ? $link['language_icon'] : $link['language'];
|
| 99 |
$title = $title ? $title : $link['title'];
|
| 100 |
if ($icon = theme('languageicons_icon', $language, $title)) {
|
| 101 |
$link['title'] = theme('languageicons_place', $link['title'], $icon);
|
| 102 |
$link['html'] = TRUE;
|
| 103 |
}
|
| 104 |
}
|
| 105 |
|
| 106 |
/**
|
| 107 |
* Theme language icon.
|
| 108 |
*
|
| 109 |
* This function can be overridden for no language icons.
|
| 110 |
*/
|
| 111 |
function theme_languageicons_icon($language, $title = NULL) {
|
| 112 |
if ($path = variable_get('languageicons_path', drupal_get_path('module', 'languageicons') .'/flags/*.png')) {
|
| 113 |
$src = base_path() . str_replace('*', $language->language, $path);
|
| 114 |
$title = $title ? $title : $language->native;
|
| 115 |
$attribs = array('class' => 'language-icon', 'alt' => $title);
|
| 116 |
if ($size = variable_get('languageicons_size', '16x12')) {
|
| 117 |
list($width, $height) = explode('x', $size);
|
| 118 |
$attribs += array('width' => $width, 'height' => $height);
|
| 119 |
}
|
| 120 |
return "<img src='$src' ". drupal_attributes($attribs) .' />';
|
| 121 |
}
|
| 122 |
}
|
| 123 |
|
| 124 |
/**
|
| 125 |
* Theme language icon and text.
|
| 126 |
*
|
| 127 |
* @ingroup themeable
|
| 128 |
*/
|
| 129 |
function theme_languageicons_place($text, $icon, $separator = ' ') {
|
| 130 |
switch (variable_get('languageicons_placement', 'before')) {
|
| 131 |
case 'after':
|
| 132 |
return $text . $separator . $icon;
|
| 133 |
case 'replace':
|
| 134 |
return $icon;
|
| 135 |
case 'before':
|
| 136 |
default:
|
| 137 |
return $icon . $separator . $text;
|
| 138 |
}
|
| 139 |
}
|