/**
* @file
* Author: Fredrik Jonsson <fredrik at combonet dot se>
* A module that adds Digg, del.icio.us, reddit and Technorati links to nodes.
*/
/**
* Implementation of hook_help().
*/
function service_links_help($section = 'admin/help#service_links') {
switch ($section) {
case 'admin/modules#description':
$output = t('Add Digg, del.icio.us, reddit, bloglines, Shadows Tag!, My Yahoo!,
My Web 2.0, Google Reader, RawSugar, Spurl, Simpy, Newsgator, Fark, Blink List,
Furl and Technorati links to nodes.');
break;
case 'admin/settings/service_links':
$output = t('<p>Here you can configure the service links.</p>');
break;
}
return $output;
}
/**
* Implementation of hook_settings().
*/
function service_links_settings() {
foreach(node_get_types() as $type => $name) {
$options[$type] = $name;
}
$form['what_links_to_show'] = array(
'#type' => 'fieldset',
'#title' => t('What links to show'),
);
$form['what_links_to_show']['service_links_show_delicious'] = array(
'#type' => 'checkbox',
'#title' => t('Show del.icio.us links'),
'#return_value' => 1,
'#default_value' => variable_get('service_links_show_delicious', '1'),
);
$form['what_links_to_show']['service_links_show_digg'] = array(
'#type' => 'checkbox',
'#title' => t('Show Digg links'),
'#return_value' => 1,
'#default_value' => variable_get('service_links_show_digg', '1'),
);
$form['what_links_to_show']['service_links_show_reddit'] = array(
'#type' => 'checkbox',
'#title' => t('Show Reddit links'),
'#return_value' => 1,
'#default_value' => variable_get('service_links_show_reddit', '1'),
);
$form['what_links_to_show']['service_links_show_technorati'] = array(
'#type' => 'checkbox',
'#title' => t('Show Technorati links'),
'#return_value' => 1,
'#default_value' => variable_get('service_links_show_technorati', '1'),
);
$form['what_links_to_show']['service_links_show_bloglines'] = array(
'#type' => 'checkbox',
'#title' => t('Show Blog Lines links'),
'#return_value' => 1,
'#default_value' => variable_get('service_links_show_bloglines', '1'),
);
$form['what_links_to_show']['service_links_show_yahoo'] = array(
'#type' => 'checkbox',
'#title' => t('Show My Yahoo! links'),
'#return_value' => 1,
'#default_value' => variable_get('service_links_show_yahoo', '1'),
);
$form['what_links_to_show']['service_links_show_google'] = array(
'#type' => 'checkbox',
'#title' => t('Show Google Reader links'),
'#return_value' => 1,
'#default_value' => variable_get('service_links_show_google', '1'),
);
$form['what_links_to_show']['service_links_show_newsgator'] = array(
'#type' => 'checkbox',
'#title' => t('Show Newsgator links'),
'#return_value' => 1,
'#default_value' => variable_get('service_links_show_newsgator', '1'),
);
$form['what_links_to_show']['service_links_show_furl'] = array(
'#type' => 'checkbox',
'#title' => t('Show Furl links'),
'#return_value' => 1,
'#default_value' => variable_get('service_links_show_furl', '1'),
);
$form['what_links_to_show']['service_links_show_simpy'] = array(
'#type' => 'checkbox',
'#title' => t('Show Simpy links'),
'#return_value' => 1,
'#default_value' => variable_get('service_links_show_simpy', '1'),
);
$form['what_links_to_show']['service_links_show_spurl'] = array(
'#type' => 'checkbox',
'#title' => t('Show Spurl links'),
'#return_value' => 1,
'#default_value' => variable_get('service_links_show_spurl', '1'),
);
$form['what_links_to_show']['service_links_show_blink'] = array(
'#type' => 'checkbox',
'#title' => t('Show Blink List links'),
'#return_value' => 1,
'#default_value' => variable_get('service_links_show_blink', '1'),
);
$form['what_links_to_show']['service_links_show_web2'] = array(
'#type' => 'checkbox',
'#title' => t('Show My Web 2.0 links'),
'#return_value' => 1,
'#default_value' => variable_get('service_links_show_web2', '1'),
);
$form['what_links_to_show']['service_links_show_rawsugar'] = array(
'#type' => 'checkbox',
'#title' => t('Show Raw Sugar Tags! links'),
'#return_value' => 1,
'#default_value' => variable_get('service_links_show_rawsugar', '1'),
);
$form['what_links_to_show']['service_links_show_shadows'] = array(
'#type' => 'checkbox',
'#title' => t('Show Shadows Tags links'),
'#return_value' => 1,
'#default_value' => variable_get('service_links_show_shadows', '1'),
);
$form['what_links_to_show']['service_links_show_fark'] = array(
'#type' => 'checkbox',
'#title' => t('Show Fark it'),
'#return_value' => 1,
'#default_value' => variable_get('service_links_show_fark', '1'),
);
$form['where_and_how_to_show_the_links'] = array(
'#type' => 'fieldset',
'#title' => t('Where and how to show the links'),
);
$form['where_and_how_to_show_the_links']['service_links_style'] = array(
'#type' => 'radios',
'#title' => t('Link style'),
'#default_value' => variable_get('service_links_style', 1),
'#options' => array('1' => t('Text links'),'2' => t('Image links'),'3'
=> t('Image and text links')),
);
$form['where_and_how_to_show_the_links']['service_links_node_types'] = array(
'#type' => 'select',
'#title' => t('Node types to display links for'),
'#default_value' => variable_get('service_links_node_types', array()),
'#options' => $options,
'#multiple' => TRUE,
);
$form['where_and_how_to_show_the_links']['service_links_main'] = array(
'#type' => 'checkbox',
'#title' => t('Show links also on nodes on front page'),
'#return_value' => 1,
'#default_value' => variable_get('service_links_main', 0),
);
return $form;
}
/**
* Implementation of hook_link().
*/
function service_links_link($type, $node = 0, $main) {
$links = array();
$node_type = in_array($node->type, variable_get('service_links_node_types',
array()), TRUE);
$links_main = variable_get('service_links_main', 0) == '1' || $main == 0 ?
'1' : '0';
if ($type == 'node' && $node_type && $links_main) {
$url = url("node/$node->nid", NULL, NULL, TRUE);
$title = drupal_urlencode($node->title);
if (variable_get('service_links_show_delicious', 1)) {
$links[] = _service_link_build_link(t('Del.icio.us'), "http://del.icio.us/post?url=$url&title=$title",
t('Bookmark this post on del.icio.us.'), 'delicious.png');
}
if (variable_get('service_links_show_digg', 1)) {
$links[] = _service_link_build_link(t('Digg it'), "http://digg.com/submit?phase=2&url=$url",
t('Digg this post on digg.com.'), 'digg.png');
}
if (variable_get('service_links_show_fark', 1)) {
$links[] = _service_link_build_link(t('Fark it!'), "http://cgi.fark.com/cgi/fark/submit.pl",
t('Fark this post on Fark.com.'), 'fark.gif');
}
if (variable_get('service_links_show_reddit', 1)) {
$links[] = _service_link_build_link(t('Reddit'), "http://reddit.com/submit?url=$url&title=$title",
t('Submit this post on reddit.com.'), 'reddit.png');
}
if (variable_get('service_links_show_technorati', 1)) {
$links[] = _service_link_build_link(t('Technorati'), "http://technorati.com/cosmos/search.html?url=$url",
t('Search Technorati for links to this post.'), 'technorati.png');
}
if (variable_get('service_links_show_furl', 1)) {
$links[] = _service_link_build_link(t('Furl'), "http://www.furl.net/storeIt.jsp?u=$url",
t('Store this link in furl.'), 'furl.gif');
}
if (variable_get('service_links_show_simpy', 1)) {
$links[] = _service_link_build_link(t('Simpy'), "http://simpy.com/simpy/LinkAdd.do?note=Hellacrazy&href=$url&title=$title&tags=$terms",
t('Submit link to Simpy.'), 'simpy.bmp');
}
if (variable_get('service_links_show_blink', 1)) {
$links[] = _service_link_build_link(t('Blink List'), "http://www.blinklist.com/index.php?Action=Blink/addblink.php&Url=$url&title=$title",
t('Submit link to Blink List.'), 'blinklist.gif');
}
if (variable_get('service_links_show_spurl', 1)) {
$links[] = _service_link_build_link(t('Spurl'), "http://www.spurl.net/spurl.php?url=$url&title=$title",
t('Submit link to Spurl.'), 'spurl.jpg');
}
if (variable_get('service_links_show_web2', 1)) {
$links[] = _service_link_build_link(t('Web 2.0'), "http://myweb2.search.yahoo.com/myresults/bookmarklet?t=$title&u=$url&d=HellaCrazy&tag=$terms",
t('Submit link to Web 2.0.'), 'yahoomyweb.gif');
}
if (variable_get('service_links_show_rawsugar', 1)) {
$links[] = _service_link_build_link(t('Tag! RawSugar'), "http://www.rawsugar.com/pages/tagger.faces?turl=$url&tttl=$title",
t('Submit link to Tag!RawSugar Account.'), 'rawsugar.png');
}
if (variable_get('service_links_show_shadows', 1)) {
$links[] = _service_link_build_link(t('Shadow Tag'), "http://www.shadows.com/features/tcr.htm?url=$url&title=$title",
t('Submit link to Shadows Tag Account.'), 'shadows.ico');
}
if (variable_get('service_links_show_bloglines', 1)) {
$links[] = _service_link_build_link(t('Bloglines'), "http://www.bloglines.com/sub/$url/feed",
t('Submit this Article to your Bloglines account.'), 'bloglines.jpg');
}
if (variable_get('service_links_show_yahoo', 1)) {
$links[] = _service_link_build_link(t('My Yahoo!'), "http://add.my.yahoo.com/rss?url=$url/feed",
t('Submit this Article to your My Yahoo account.'), 'web2.ico');
}
if (variable_get('service_links_show_google', 1)) {
$links[] = _service_link_build_link(t('Google Reader'), "http://fusion.google.com/add?feedurl=$url/feed",
t('Submit this Article to your Google Reader account.'), 'google.gif');
}
if (variable_get('service_links_show_newsgator', 1)) {
$links[] = _service_link_build_link(t('Newsgator'), "http://www.newsgator.com/ngs/subscriber/subext.aspx?url=$url/feed",
t('Submit this Article to your Newsgator Reader account.'), 'newsgator.jpg');
}
}
return $links;
}
function _service_link_build_link($text, $url, $title, $image) {
global $base_path;
if (variable_get('service_links_style', 1) == '3') {
$link = '<a href="'. check_url($url) .'" title="'. $title
.'"><img src="'. $base_path . drupal_get_path('module', 'service_links')
.'/'. $image .'" alt="'. $text .'" /> '. $text .'</a>';
}
elseif (variable_get('service_links_style', 1) == '2') {
$link = '<a href="'. check_url($url) .'" title="'. $title
.'"><img src="'. $base_path . drupal_get_path('module', 'service_links')
.'/'. $image .'" alt="'. $text .'" /></a>';
}
else {
$link = '<a href="'. check_url($url) .'" title="'. $title
.'">'. $text .'</a>';
}
return $link;
}
?>