Skip to content

Commit

Permalink
Begin to rework this module to use font-awesome icons instead of thes…
Browse files Browse the repository at this point in the history
…e over-stylized ones.
  • Loading branch information
Jen Lampton committed Dec 29, 2017
1 parent b0cd7b6 commit 25c663e
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 94 deletions.
1 change: 1 addition & 0 deletions on_the_web.admin.inc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function on_the_web_settings_form($form, &$form_state) {
'#type' => 'radios',
'#title' => t('Icon type'),
'#options' => array(
'font' => t('FontAwesome icon font'),
'anchor' => t('Background image on anchor'),
'image' => t('Image tags in anchor'),
),
Expand Down
2 changes: 1 addition & 1 deletion on_the_web.api.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ function hook_on_the_web_get_services_alter(&$services) {
$services = array('facebook' => $face)+$services;

// Add an additional service.
$services['soundcloud'] = array('name' => 'SoundCloud');
$services['github'] = array('name' => 'GitHub');
}
120 changes: 67 additions & 53 deletions on_the_web.module
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,19 @@
*/

/**
* Implementation of hook_block_info().
* Implements hook_config_info().
*/
function on_the_web_config_info() {
$prefixes['on_the_web.settings'] = array(
'label' => t('On The Web Settings'),
'group' => t('Configuration'),
);

return $prefixes;
}

/**
* Implements hook_block_info().
*/
function on_the_web_menu() {
$items['admin/config/services/on_the_web'] = array(
Expand All @@ -21,19 +33,7 @@ function on_the_web_menu() {
}

/**
* Implements hook_config_info().
*/
function on_the_web_config_info() {
$prefixes['on_the_web.settings'] = array(
'label' => t('Links to social media sites, and their order.'),
'group' => t('Configuration'),
);

return $prefixes;
}

/**
* Implementation of hook_block_info().
* Implements hook_block_info().
*/
function on_the_web_block_info() {
$blocks['social_links'] = array(
Expand All @@ -45,7 +45,7 @@ function on_the_web_block_info() {
}

/**
* Implementation of hook_block_configure().
* Implements hook_block_configure().
*/
function on_the_web_block_configure($delta = 'social_links', $settings = array()) {
$form = array();
Expand Down Expand Up @@ -126,7 +126,7 @@ function on_the_web_block_configure($delta = 'social_links', $settings = array()
}

/**
* Implementation of hook_block_view().
* Implements hook_block_view().
*/
function on_the_web_block_view($delta = 'social_links', $settings = array(), $contexts = array()) {
$block = array(
Expand Down Expand Up @@ -158,7 +158,7 @@ function on_the_web_display_block($delta, $settings = array(), $contexts = array
$name = t('me');
}

// Get the display style, and enabled icons.
// Get the display style.
$display = $settings['services']['display'];
if ($display == 'manual') {
$enabled = $settings['services']['enabled'];
Expand All @@ -170,7 +170,7 @@ function on_the_web_display_block($delta, $settings = array(), $contexts = array
foreach ($services as $service => $info) {
$link = $config->get($service . '_page');

if (($display == 'auto' && ($link != '')) ||
if (($display == 'auto' && ($link != '')) ||
($display == 'manual' && array_key_exists($service, $enabled) && $enabled[$service] === $service)) {

if ($service != 'rss') {
Expand All @@ -188,6 +188,8 @@ function on_the_web_display_block($delta, $settings = array(), $contexts = array
'#theme' => 'on_the_web_item',
'#service' => $service,
'#link' => $link,
'#icon' => $info['fa'],
'#size' => $size,
'#title' => $title,
'#classes' => $classes,
'#weight' => $weight,
Expand All @@ -200,51 +202,30 @@ function on_the_web_display_block($delta, $settings = array(), $contexts = array
'css' => array(backdrop_get_path('module', 'on_the_web') . '/css/on_the_web.css'),
);
}
elseif ($type == 'font') {
$links['#attached'] = array(
'css' => array('https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css', array('external' => TRUE)),
);
}
}

return backdrop_render($links);
}

/**
* Helper function: Gets the available services.
*
* @return array
* List of services with icons.
*/
function on_the_web_get_services() {
$services = array(
'twitter' => array('name' => 'Twitter'),
'facebook' => array('name' => 'Facebook'),
'pinterest' => array('name' => 'Pinterest'),
'instagram' => array('name' => 'Instagram'),
'google' => array('name' => 'Google+'),
'youtube' => array('name' => 'YouTube'),
'flickr' => array('name' => 'Flickr'),
'myspace' => array('name' => 'MySpace'),
'linkedin' => array('name' => 'LinkedIn'),
'itunes' => array('name' => 'iTunes'),
'delicious' => array('name' => 'Delicious'),
'soundcloud' => array('name' => 'Soundcloud'),
'friendfeed' => array('name' => 'FriendFeed'),
'rss' => array('name' => 'RSS'),
);

backdrop_alter('on_the_web_get_services', $services);

return $services;
}

/**
* Implementation of hook_theme().
* Implements hook_theme().
*/
function on_the_web_theme($existing, $type, $theme, $path) {
return array(
'on_the_web_item' => array(
'variables' => array('service' => NULL, 'link' => NULL, 'title' => NULL, 'classes' => array()),
'file' => 'on_the_web.theme.inc',
),
'on_the_web_image' => array(
'variables' => array('service' => NULL, 'title' => NULL),
'variables' => array(
'service' => NULL,
'link' => NULL,
'icon' => 'fa-fort-awesome',
'size' => 'sm',
'title' => NULL,
'classes' => array(),
),
'file' => 'on_the_web.theme.inc',
),

Expand All @@ -255,3 +236,36 @@ function on_the_web_theme($existing, $type, $theme, $path) {
),
);
}

/*******************************************************************************
* Untilty functions.
*******************************************************************************/

/**
* Gets the available services.
*
* @return array
* List of services with icons.
*/
function on_the_web_get_services() {
$services = array(
'twitter' => array('name' => 'Twitter', 'fa' => 'fa-twitter-square'),
'facebook' => array('name' => 'Facebook', 'fa' => 'fa-facebook-square'),
'pinterest' => array('name' => 'Pinterest', 'fa' => 'fa-pinterest-square'),
'instagram' => array('name' => 'Instagram', 'fa' => 'fa-instagram'),
'google' => array('name' => 'Google+', 'fa' => 'fa-google-plus-square'),
'youtube' => array('name' => 'YouTube', 'fa' => 'fa-youtube-square'),
'flickr' => array('name' => 'Flickr', 'fa' => 'fa-flickr'),
'linkedin' => array('name' => 'LinkedIn', 'fa' => 'fa-linkedin-square'),
'myspace' => array('name' => 'MySpace', 'fa' => 'fa-user'),
'itunes' => array('name' => 'iTunes', 'fa' => 'fa-apple'),
'delicious' => array('name' => 'Delicious', 'fa' => 'fa-delicious'),
'soundcloud' => array('name' => 'Soundcloud', 'fa' => 'fa-soundcloud'),
'github' => array('name' => 'GitHub', 'fa' => 'fa-github-square'),
'rss' => array('name' => 'RSS', 'fa' => 'fa-rss-square'),
);

backdrop_alter('on_the_web_get_services', $services);

return $services;
}
56 changes: 16 additions & 40 deletions on_the_web.theme.inc
Original file line number Diff line number Diff line change
Expand Up @@ -20,69 +20,45 @@
function theme_on_the_web_item($variables) {
$service = $variables['service'];
$link = $variables['link'];
$icon = $variables['icon'];
$size = $variables['size'];
$title = $variables['title'];
$classes = $variables['classes'];
$link_classes = $variables['classes'];

$config = config('on_the_web.settings');
$type = $config->get('type');
$target = $config->get('target');

// Determine attributes for the link
$attributes = array(
'class' => $classes,
'class' => $link_classes,
'title' => $title,
'rel' => 'nofollow',
);
if ($target == TRUE) {
$attributes['target'] = '_blank';
}
$options = array('attributes' => $attributes);
$options = array('attributes' => $attributes, 'html' => TRUE);

if ($type == 'image') {
$inner = theme('on_the_web_image', array('service' => $service, 'title' => $title));
$options['html'] = TRUE;
$icon_classes = array('fa', $icon, 'fa-fw');
if ($size == 'lg') {
$icon_classes[] = 'fa-2x';
}
else {
$inner = $title;

$text = '<i class="' . implode(' ', $icon_classes) . '"></i>';

// Special hack for myspace, three user icons instead.
if ($service == 'myspace') {
$text .= '<i class="fa ' . $icon . ' fa-fw" style="margin-left: -1.33em"></i>';
$text .= '<i class="fa ' . $icon . ' fa-fw" style="margin-left: -1.66em"></i>';
}

// Link the image and wrap it in a span.
$linked_image = l($inner, $link, $options);
$linked_image = l($text, $link, $options);

return $linked_image;
}

/**
* Theme function
*
* @param $service
* Icon for appropriate service.
* @param $title
* Title attribute for the link tag.
*
* @return
* Icon image of appropriate size.
*/
function theme_on_the_web_image($variables) {
$service = $variables['service'];
$title = $variables['title'];

// Get the size.
$size = config_get('on_the_web.settings', 'size');

// Assemble necessary variables for building the image.
$variables = array(
'uri' => backdrop_get_path('module', 'on_the_web') . '/images/' . $size . '/' . $service . '.png',
'alt' => $title,
'title' => $title,
);

// Build the img tag.
$image = theme('image', $variables);

return $image;
}

/**
* Theme the drag-and-drop form.
*
Expand Down

0 comments on commit 25c663e

Please sign in to comment.