Skip to content

Commit 25c663e

Browse files
author
Jen Lampton
committed
Begin to rework this module to use font-awesome icons instead of these over-stylized ones.
1 parent b0cd7b6 commit 25c663e

File tree

4 files changed

+85
-94
lines changed

4 files changed

+85
-94
lines changed

on_the_web.admin.inc

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ function on_the_web_settings_form($form, &$form_state) {
1515
'#type' => 'radios',
1616
'#title' => t('Icon type'),
1717
'#options' => array(
18+
'font' => t('FontAwesome icon font'),
1819
'anchor' => t('Background image on anchor'),
1920
'image' => t('Image tags in anchor'),
2021
),

on_the_web.api.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ function hook_on_the_web_get_services_alter(&$services) {
2222
$services = array('facebook' => $face)+$services;
2323

2424
// Add an additional service.
25-
$services['soundcloud'] = array('name' => 'SoundCloud');
25+
$services['github'] = array('name' => 'GitHub');
2626
}

on_the_web.module

+67-53
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,19 @@
55
*/
66

77
/**
8-
* Implementation of hook_block_info().
8+
* Implements hook_config_info().
9+
*/
10+
function on_the_web_config_info() {
11+
$prefixes['on_the_web.settings'] = array(
12+
'label' => t('On The Web Settings'),
13+
'group' => t('Configuration'),
14+
);
15+
16+
return $prefixes;
17+
}
18+
19+
/**
20+
* Implements hook_block_info().
921
*/
1022
function on_the_web_menu() {
1123
$items['admin/config/services/on_the_web'] = array(
@@ -21,19 +33,7 @@ function on_the_web_menu() {
2133
}
2234

2335
/**
24-
* Implements hook_config_info().
25-
*/
26-
function on_the_web_config_info() {
27-
$prefixes['on_the_web.settings'] = array(
28-
'label' => t('Links to social media sites, and their order.'),
29-
'group' => t('Configuration'),
30-
);
31-
32-
return $prefixes;
33-
}
34-
35-
/**
36-
* Implementation of hook_block_info().
36+
* Implements hook_block_info().
3737
*/
3838
function on_the_web_block_info() {
3939
$blocks['social_links'] = array(
@@ -45,7 +45,7 @@ function on_the_web_block_info() {
4545
}
4646

4747
/**
48-
* Implementation of hook_block_configure().
48+
* Implements hook_block_configure().
4949
*/
5050
function on_the_web_block_configure($delta = 'social_links', $settings = array()) {
5151
$form = array();
@@ -126,7 +126,7 @@ function on_the_web_block_configure($delta = 'social_links', $settings = array()
126126
}
127127

128128
/**
129-
* Implementation of hook_block_view().
129+
* Implements hook_block_view().
130130
*/
131131
function on_the_web_block_view($delta = 'social_links', $settings = array(), $contexts = array()) {
132132
$block = array(
@@ -158,7 +158,7 @@ function on_the_web_display_block($delta, $settings = array(), $contexts = array
158158
$name = t('me');
159159
}
160160

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

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

176176
if ($service != 'rss') {
@@ -188,6 +188,8 @@ function on_the_web_display_block($delta, $settings = array(), $contexts = array
188188
'#theme' => 'on_the_web_item',
189189
'#service' => $service,
190190
'#link' => $link,
191+
'#icon' => $info['fa'],
192+
'#size' => $size,
191193
'#title' => $title,
192194
'#classes' => $classes,
193195
'#weight' => $weight,
@@ -200,51 +202,30 @@ function on_the_web_display_block($delta, $settings = array(), $contexts = array
200202
'css' => array(backdrop_get_path('module', 'on_the_web') . '/css/on_the_web.css'),
201203
);
202204
}
205+
elseif ($type == 'font') {
206+
$links['#attached'] = array(
207+
'css' => array('https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css', array('external' => TRUE)),
208+
);
209+
}
203210
}
204211

205212
return backdrop_render($links);
206213
}
207214

208215
/**
209-
* Helper function: Gets the available services.
210-
*
211-
* @return array
212-
* List of services with icons.
213-
*/
214-
function on_the_web_get_services() {
215-
$services = array(
216-
'twitter' => array('name' => 'Twitter'),
217-
'facebook' => array('name' => 'Facebook'),
218-
'pinterest' => array('name' => 'Pinterest'),
219-
'instagram' => array('name' => 'Instagram'),
220-
'google' => array('name' => 'Google+'),
221-
'youtube' => array('name' => 'YouTube'),
222-
'flickr' => array('name' => 'Flickr'),
223-
'myspace' => array('name' => 'MySpace'),
224-
'linkedin' => array('name' => 'LinkedIn'),
225-
'itunes' => array('name' => 'iTunes'),
226-
'delicious' => array('name' => 'Delicious'),
227-
'soundcloud' => array('name' => 'Soundcloud'),
228-
'friendfeed' => array('name' => 'FriendFeed'),
229-
'rss' => array('name' => 'RSS'),
230-
);
231-
232-
backdrop_alter('on_the_web_get_services', $services);
233-
234-
return $services;
235-
}
236-
237-
/**
238-
* Implementation of hook_theme().
216+
* Implements hook_theme().
239217
*/
240218
function on_the_web_theme($existing, $type, $theme, $path) {
241219
return array(
242220
'on_the_web_item' => array(
243-
'variables' => array('service' => NULL, 'link' => NULL, 'title' => NULL, 'classes' => array()),
244-
'file' => 'on_the_web.theme.inc',
245-
),
246-
'on_the_web_image' => array(
247-
'variables' => array('service' => NULL, 'title' => NULL),
221+
'variables' => array(
222+
'service' => NULL,
223+
'link' => NULL,
224+
'icon' => 'fa-fort-awesome',
225+
'size' => 'sm',
226+
'title' => NULL,
227+
'classes' => array(),
228+
),
248229
'file' => 'on_the_web.theme.inc',
249230
),
250231

@@ -255,3 +236,36 @@ function on_the_web_theme($existing, $type, $theme, $path) {
255236
),
256237
);
257238
}
239+
240+
/*******************************************************************************
241+
* Untilty functions.
242+
*******************************************************************************/
243+
244+
/**
245+
* Gets the available services.
246+
*
247+
* @return array
248+
* List of services with icons.
249+
*/
250+
function on_the_web_get_services() {
251+
$services = array(
252+
'twitter' => array('name' => 'Twitter', 'fa' => 'fa-twitter-square'),
253+
'facebook' => array('name' => 'Facebook', 'fa' => 'fa-facebook-square'),
254+
'pinterest' => array('name' => 'Pinterest', 'fa' => 'fa-pinterest-square'),
255+
'instagram' => array('name' => 'Instagram', 'fa' => 'fa-instagram'),
256+
'google' => array('name' => 'Google+', 'fa' => 'fa-google-plus-square'),
257+
'youtube' => array('name' => 'YouTube', 'fa' => 'fa-youtube-square'),
258+
'flickr' => array('name' => 'Flickr', 'fa' => 'fa-flickr'),
259+
'linkedin' => array('name' => 'LinkedIn', 'fa' => 'fa-linkedin-square'),
260+
'myspace' => array('name' => 'MySpace', 'fa' => 'fa-user'),
261+
'itunes' => array('name' => 'iTunes', 'fa' => 'fa-apple'),
262+
'delicious' => array('name' => 'Delicious', 'fa' => 'fa-delicious'),
263+
'soundcloud' => array('name' => 'Soundcloud', 'fa' => 'fa-soundcloud'),
264+
'github' => array('name' => 'GitHub', 'fa' => 'fa-github-square'),
265+
'rss' => array('name' => 'RSS', 'fa' => 'fa-rss-square'),
266+
);
267+
268+
backdrop_alter('on_the_web_get_services', $services);
269+
270+
return $services;
271+
}

on_the_web.theme.inc

+16-40
Original file line numberDiff line numberDiff line change
@@ -20,69 +20,45 @@
2020
function theme_on_the_web_item($variables) {
2121
$service = $variables['service'];
2222
$link = $variables['link'];
23+
$icon = $variables['icon'];
24+
$size = $variables['size'];
2325
$title = $variables['title'];
24-
$classes = $variables['classes'];
26+
$link_classes = $variables['classes'];
2527

2628
$config = config('on_the_web.settings');
2729
$type = $config->get('type');
2830
$target = $config->get('target');
2931

3032
// Determine attributes for the link
3133
$attributes = array(
32-
'class' => $classes,
34+
'class' => $link_classes,
3335
'title' => $title,
3436
'rel' => 'nofollow',
3537
);
3638
if ($target == TRUE) {
3739
$attributes['target'] = '_blank';
3840
}
39-
$options = array('attributes' => $attributes);
41+
$options = array('attributes' => $attributes, 'html' => TRUE);
4042

41-
if ($type == 'image') {
42-
$inner = theme('on_the_web_image', array('service' => $service, 'title' => $title));
43-
$options['html'] = TRUE;
43+
$icon_classes = array('fa', $icon, 'fa-fw');
44+
if ($size == 'lg') {
45+
$icon_classes[] = 'fa-2x';
4446
}
45-
else {
46-
$inner = $title;
47+
48+
$text = '<i class="' . implode(' ', $icon_classes) . '"></i>';
49+
50+
// Special hack for myspace, three user icons instead.
51+
if ($service == 'myspace') {
52+
$text .= '<i class="fa ' . $icon . ' fa-fw" style="margin-left: -1.33em"></i>';
53+
$text .= '<i class="fa ' . $icon . ' fa-fw" style="margin-left: -1.66em"></i>';
4754
}
4855

4956
// Link the image and wrap it in a span.
50-
$linked_image = l($inner, $link, $options);
57+
$linked_image = l($text, $link, $options);
5158

5259
return $linked_image;
5360
}
5461

55-
/**
56-
* Theme function
57-
*
58-
* @param $service
59-
* Icon for appropriate service.
60-
* @param $title
61-
* Title attribute for the link tag.
62-
*
63-
* @return
64-
* Icon image of appropriate size.
65-
*/
66-
function theme_on_the_web_image($variables) {
67-
$service = $variables['service'];
68-
$title = $variables['title'];
69-
70-
// Get the size.
71-
$size = config_get('on_the_web.settings', 'size');
72-
73-
// Assemble necessary variables for building the image.
74-
$variables = array(
75-
'uri' => backdrop_get_path('module', 'on_the_web') . '/images/' . $size . '/' . $service . '.png',
76-
'alt' => $title,
77-
'title' => $title,
78-
);
79-
80-
// Build the img tag.
81-
$image = theme('image', $variables);
82-
83-
return $image;
84-
}
85-
8662
/**
8763
* Theme the drag-and-drop form.
8864
*

0 commit comments

Comments
 (0)