countryicons.module in Country Icons 6.2
Same filename and directory in other branches
A collection of country icons, and an API for retrieving them.
File
countryicons.moduleView source
<?php
/**
* @file
* A collection of country icons, and an API for retrieving them.
*/
/**
* Advertise the current countryicons api version.
*/
function countryicons_api_version() {
return 2.0;
}
/**
* Implementation of hook_theme().
*/
function countryicons_theme() {
return array(
'countryicons_icon' => array(
'arguments' => array(
'code' => NULL,
'iconset' => NULL,
'alt' => '',
'title' => '',
'attributes' => NULL,
'display_unkown' => TRUE,
),
'file' => 'countryicons.theme.inc',
),
'countryicons_icon_sprite' => array(
'arguments' => array(
'code' => NULL,
'iconset' => NULL,
),
'file' => 'countryicons.theme.inc',
),
'countryicons_help' => array(
'arguments' => array(
'iconsets' => array(),
),
'template' => 'countryicons-help',
),
);
}
/**
* Implementation of hook_help().
*/
function countryicons_help($path, $arg) {
switch ($path) {
case 'admin/help#countryicons':
return theme('countryicons_help', countryicons_get_iconsets());
}
}
/**
* Get all iconsets and their details.
*
* @param $reset
* If TRUE, clear the cache and fetch the information again.
* @return
* array of iconset objects.
*/
function countryicons_get_iconsets($reset = FALSE) {
static $iconsets;
if ($reset || !isset($iconsets)) {
$iconsets = module_invoke_all('iconset_info');
}
return $iconsets;
}
/**
* Get an iconsets details.
*
* @param $iconset
* The iconset name.
* @return
* object with requested iconset.
*/
function countryicons_get_iconset($iconset) {
$iconsets = countryicons_get_iconsets();
return $iconsets[$iconset];
}
/**
* Get the path to an icon.
*
* @param $code
* A two letter ISO3166 country code.
* @param $iconset
* The icon set to use.
* @return
* If icon exists a string containing the path to the image file, else NULL.
*/
function countryicons_get_icon_path($code, $iconset) {
$iconset = countryicons_get_iconset($iconset);
if (!empty($iconset) && !empty($code)) {
$icon_path = $iconset->path . '/' . drupal_strtolower($code) . '.' . $iconset->extension;
if (file_exists($icon_path)) {
return $icon_path;
}
}
}
/**
* Get the URL to an icon.
*
* @param $code
* A two letter ISO3166 country code.
* @param $iconset
* The icon set to use.
* @return
* If icon exists a string containing the url to the image file, else NULL.
*/
function countryicons_get_icon_url($code, $iconset) {
$icon_path = countryicons_get_icon_path($code, $iconset);
if (!empty($icon_path)) {
return url($icon_path, array(
'absolute' => TRUE,
));
}
}
Functions
Name | Description |
---|---|
countryicons_api_version | Advertise the current countryicons api version. |
countryicons_get_iconset | Get an iconsets details. |
countryicons_get_iconsets | Get all iconsets and their details. |
countryicons_get_icon_path | Get the path to an icon. |
countryicons_get_icon_url | Get the URL to an icon. |
countryicons_help | Implementation of hook_help(). |
countryicons_theme | Implementation of hook_theme(). |