addclips.module 5.x-1.x head
<?php
// $Id: addclips.module,v 1.0 2008/03/11 0829 Exp $
/**
* Implementation of hook_menu().
*/
function addclips_menu($may_cache) {
$items = array();
if ($may_cache) {
$items[] = array(
'path' => 'admin/settings/addclips',
'title' => t('AddClips'),
'description' => t('Configure the AddClips.'),
'callback' => 'drupal_get_form',
'callback arguments' => array('addclips_settings'),
'access' => user_access('administer site configuration'),
'type' => MENU_NORMAL_ITEM,
);
}
if (module_exists('colorpicker')) {
drupal_add_css(drupal_get_path('module', 'addclips') . '/colorpicker.css', 'module');
}
return $items;
}
/**
* Implementation of hook_help().
*/
function addclips_help($section) {
switch ($section) {
case 'admin/settings/addclips' :
return t('The AddClips module is a module to add a button to social bookmark to using service of AddClips.<br />See <a href="@url">AddClips</a> website for details.', array('@url' => 'http://www.addclips.org/'));
break;
}
}
/**
* Menu callback; Return AddClips settings form.
*/
function addclips_settings() {
$form['addclips_use'] = array(
'#type' => 'checkbox',
'#title' => t('Use AddClips'),
'#description' => t('If checked this add a social bookmark button of AddClips.'),
'#default_value' => variable_get('addclips_use', 0),
);
$form['addclips_id'] = array(
'#type' => 'textfield',
'#title' => t('AddClips ID'),
'#description' => t('Input the AddClips ID. It is the part of "addclipsId =" in the created cord of AddClips website.'),
'#default_value' => variable_get('addclips_id', ''),
'#size' => 20,
);
$form['addclips_object'] = array(
'#type' => 'select',
'#title' => t('Bookmark object'),
'#description' => t('Choose the object of the bookmarks.'),
'#options' => array(
'site' => t('The index page of this site'),
'page' => t('Each contents in this site'),
),
'#default_value' => variable_get('addclips_object', 'page'),
);
$form['addclips_view'] = array(
'#type' => 'select',
'#title' => t('AddClips View'),
'#description' => t('Choose the view point of the AddClips.'),
'#options' => array(
'both' => t('Both (Teaser and full node)'),
'node' => t('Full node'),
'teaser' => t('Teaser'),
),
'#default_value' => variable_get('addclips_view', 'both'),
);
$node_types = node_get_types('names');
$node_types['---'] = t('- Not excluded -');
$form['addclips_nodetypes_exclude'] = array(
'#type' => 'select',
'#multiple' => true,
'#title' => t('Excluded node types'),
'#description' => t('Select the node types to exclude from use AddClips button.'),
'#default_value' => variable_get('addclips_nodetypes_exclude', array()),
'#options' => $node_types,
);
$form['addclips_type'] = array(
'#type' => 'select',
'#title' => t('Button type'),
'#description' => t('Choose the button type.'),
'#options' => array(
1 => t('"Bookmark" character string and 5 icons'),
0 => t('9 icons'),
2 => t('"Bookmark" character string and 2 icons'),
5 => t('5 icons'),
3 => t('"Bookmark" short character string and 2 icons'),
4 => t('Icon'),
),
'#default_value' => variable_get('addclips_type', 5),
);
$form['addclips_valign'] = array(
'#type' => 'select',
'#title' => t('Vertical align of the button'),
'#description' => t('Choose the vertical align of the button.'),
'#options' => array(
'middle' => t('Align middle'),
'top' => t('Align top'),
'bottom' => t('Align bottom'),
),
'#default_value' => variable_get('addclips_valign', 'middle'),
);
$form['addclips_colors'] = array(
'#type' => 'fieldset',
'#title' => t('Color settings of the overlay window'),
'#description' => t('Choose the color set. When you chose custom setting, set a color below.'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#prefix' => '<div class="addclips-colors">',
'#suffix' => '</div>',
);
$form['addclips_colors']['addclips_colorset'] = array(
'#type' => 'select',
'#title' => t('Color Set'),
'#options' => array(
'#78BE44,#D1E9C0,#666666' => t('Green (Default)'),
'#FF4646,#FFACAC,#FFFFFF' => t('Red'),
'#0080FF,#7AB1F5,#FFFFFF' => t('Blue'),
'#FF6600,#FF9900,#FFFFFF' => t('Orange'),
'#999999,#F6F6F6,#666666' => t('Gray'),
'#000000,#333333,#ffffff' => t('Black'),
'custom' => t('Custom'),
),
'#default_value' => variable_get('addclips_colorset', '#2385c2,#5ab5ee,#494949'),
);
if (module_exists('colorpicker')) {
$form['addclips_colors']['addclips_colorpicker'] = array(
'#type' => 'colorpicker',
'#title' => t('Color picker'),
'#prefix' => '<div class="colorsettings-colorpicker">',
'#suffix' => '</div>',
);
$form['addclips_colors']['addclips_b_pickcolor'] = array(
'#type' => 'colorpicker_textfield',
'#title' => t('Border color'),
'#default_value' => variable_get('addclips_b_pickcolor', '#'),
'#colorpicker' => 'addclips_colorpicker',
'#maxlength' => 7,
);
$form['addclips_colors']['addclips_n_pickcolor'] = array(
'#type' => 'colorpicker_textfield',
'#title' => t('Background color'),
'#default_value' => variable_get('addclips_n_pickcolor', '#'),
'#colorpicker' => 'addclips_colorpicker',
'#maxlength' => 7,
);
$form['addclips_colors']['addclips_t_pickcolor'] = array(
'#type' => 'colorpicker_textfield',
'#title' => t('Text color'),
'#default_value' => variable_get('addclips_t_pickcolor', '#'),
'#colorpicker' => 'addclips_colorpicker',
'#maxlength' => 7,
);
}
else {
$form['addclips_colors']['addclips_b_color'] = array(
'#type' => 'textfield',
'#title' => t('Border color'),
'#default_value' => variable_get('addclips_b_color', ''),
'#maxlength' => 7,
'#size' => 15,
);
$form['addclips_colors']['addclips_n_color'] = array(
'#type' => 'textfield',
'#title' => t('Background color'),
'#default_value' => variable_get('addclips_n_color', ''),
'#maxlength' => 7,
'#size' => 15,
);
$form['addclips_colors']['addclips_t_color'] = array(
'#type' => 'textfield',
'#title' => t('Text color'),
'#default_value' => variable_get('addclips_t_color', ''),
'#maxlength' => 7,
'#size' => 15,
);
}
return system_settings_form($form);
}
/**
* Implementation of hook_link().
*/
function addclips_link($type, $node = NULL, $teaser = FALSE) {
$links = array();
if ($type == 'node' && variable_get('addclips_use','') == 1 && variable_get('addclips_id', '') && !in_array($node->type, variable_get('addclips_nodetypes_exclude', array()))) {
// Get values
global $base_url;
if (variable_get('addclips_object', 'page') == 'site') {
$addclips_url = $base_url;
$sitename = array(variable_get('site_name', 'Drupal'));
if (variable_get('site_slogan', '')) : $sitename[] = str_replace("'", "\'", variable_get('site_slogan', '')); endif;
$addclips_title = implode(' | ', $sitename);
}
else {
$addclips_url = $base_url . '/' . drupal_get_path_alias('node/' . $node->nid);
$addclips_title = str_replace("'", "\'", $node->title);
}
$addclips_id = variable_get('addclips_id', '');
$addclips_type = variable_get('addclips_type', 5);
$addclips_valign = variable_get('addclips_valign', 'middle');
$addclips_color = addclips_get_color();
// AddClops Codes (c) 2006-2008 AddClips
$addclips_code = '<!-- AddClips Code START -->' . "\n";
$addclips_code .= '<script type="text/javascript">' . "\n";
$addclips_code .= " AddClipsUrl = '" . $addclips_url . "';" . "\n";
$addclips_code .= " AddClipsTitle = '" . $addclips_title . "';" . "\n";
$addclips_code .= " AddClipsId = '" . $addclips_id . "';" . "\n";
$addclips_code .= " AddClipsBcolor ='" . $addclips_color['b'] . "';" . "\n";
$addclips_code .= " AddClipsNcolor ='" . $addclips_color['n'] . "';" . "\n";
$addclips_code .= " AddClipsTcolor ='" . $addclips_color['t'] . "';" . "\n";
$addclips_code .= " AddClipsType ='" . $addclips_type . "';" . "\n";
$addclips_code .= " AddClipsVerticalAlign ='" . $addclips_valign . "'; " . "\n";
$addclips_code .= '</script><script type="text/javascript" src="http://js.addclips.org/v2/addclips.js" charset="utf-8"></script>' . "\n";
$addclips_code .= '<!-- AddClips Code END -->';
if (variable_get('addclips_view', 'both') == 'both' || (variable_get('addclips_view', 'both') == 'node' && !$teaser) || (variable_get('addclips_view', 'both') == 'teaser' && $teaser)) {
$links['addclips'] = array(
'title' => $addclips_code,
'html' => TRUE,
);
}
}
return $links;
}
/**
* Helper function for hook_link().
*/
function addclips_get_color() {
$color['b'] = '#78BE44';
$color['n'] = '#D1E9C0';
$color['t'] = '#666666';
$colorset = variable_get('addclips_colorset', '#2385c2,#5ab5ee,#494949');
if ($colorset) {
if ($colorset == 'custom') {
if (module_exists('colorpicker')) {
$b_color = variable_get('addclips_b_pickcolor', '#');
$n_color = variable_get('addclips_n_pickcolor', '#');
$t_color = variable_get('addclips_t_pickcolor', '#');
if ($b_color && $b_color != '#') : $color['b'] = $b_color; endif;
if ($n_color && $n_color != '#') : $color['n'] = $n_color; endif;
if ($t_color && $t_color != '#') : $color['t'] = $t_color; endif;
}
else {
$b_color = variable_get('addclips_b_color', '');
$n_color = variable_get('addclips_n_color', '');
$t_color = variable_get('addclips_t_color', '');
if ($b_color) : $color['b'] = $b_color; endif;
if ($n_color) : $color['n'] = $n_color; endif;
if ($t_color) : $color['t'] = $t_color; endif;
}
}
else {
list($color['b'], $color['n'], $color['t']) = explode(',', $colorset);
}
}
return $color;
}
// $Id: addclips.module,v 1.0 2008/03/11 0829 Exp $
/**
* Implementation of hook_menu().
*/
function addclips_menu($may_cache) {
$items = array();
if ($may_cache) {
$items[] = array(
'path' => 'admin/settings/addclips',
'title' => t('AddClips'),
'description' => t('Configure the AddClips.'),
'callback' => 'drupal_get_form',
'callback arguments' => array('addclips_settings'),
'access' => user_access('administer site configuration'),
'type' => MENU_NORMAL_ITEM,
);
}
if (module_exists('colorpicker')) {
drupal_add_css(drupal_get_path('module', 'addclips') . '/colorpicker.css', 'module');
}
return $items;
}
/**
* Implementation of hook_help().
*/
function addclips_help($section) {
switch ($section) {
case 'admin/settings/addclips' :
return t('The AddClips module is a module to add a button to social bookmark to using service of AddClips.<br />See <a href="@url">AddClips</a> website for details.', array('@url' => 'http://www.addclips.org/'));
break;
}
}
/**
* Menu callback; Return AddClips settings form.
*/
function addclips_settings() {
$form['addclips_use'] = array(
'#type' => 'checkbox',
'#title' => t('Use AddClips'),
'#description' => t('If checked this add a social bookmark button of AddClips.'),
'#default_value' => variable_get('addclips_use', 0),
);
$form['addclips_id'] = array(
'#type' => 'textfield',
'#title' => t('AddClips ID'),
'#description' => t('Input the AddClips ID. It is the part of "addclipsId =" in the created cord of AddClips website.'),
'#default_value' => variable_get('addclips_id', ''),
'#size' => 20,
);
$form['addclips_object'] = array(
'#type' => 'select',
'#title' => t('Bookmark object'),
'#description' => t('Choose the object of the bookmarks.'),
'#options' => array(
'site' => t('The index page of this site'),
'page' => t('Each contents in this site'),
),
'#default_value' => variable_get('addclips_object', 'page'),
);
$form['addclips_view'] = array(
'#type' => 'select',
'#title' => t('AddClips View'),
'#description' => t('Choose the view point of the AddClips.'),
'#options' => array(
'both' => t('Both (Teaser and full node)'),
'node' => t('Full node'),
'teaser' => t('Teaser'),
),
'#default_value' => variable_get('addclips_view', 'both'),
);
$node_types = node_get_types('names');
$node_types['---'] = t('- Not excluded -');
$form['addclips_nodetypes_exclude'] = array(
'#type' => 'select',
'#multiple' => true,
'#title' => t('Excluded node types'),
'#description' => t('Select the node types to exclude from use AddClips button.'),
'#default_value' => variable_get('addclips_nodetypes_exclude', array()),
'#options' => $node_types,
);
$form['addclips_type'] = array(
'#type' => 'select',
'#title' => t('Button type'),
'#description' => t('Choose the button type.'),
'#options' => array(
1 => t('"Bookmark" character string and 5 icons'),
0 => t('9 icons'),
2 => t('"Bookmark" character string and 2 icons'),
5 => t('5 icons'),
3 => t('"Bookmark" short character string and 2 icons'),
4 => t('Icon'),
),
'#default_value' => variable_get('addclips_type', 5),
);
$form['addclips_valign'] = array(
'#type' => 'select',
'#title' => t('Vertical align of the button'),
'#description' => t('Choose the vertical align of the button.'),
'#options' => array(
'middle' => t('Align middle'),
'top' => t('Align top'),
'bottom' => t('Align bottom'),
),
'#default_value' => variable_get('addclips_valign', 'middle'),
);
$form['addclips_colors'] = array(
'#type' => 'fieldset',
'#title' => t('Color settings of the overlay window'),
'#description' => t('Choose the color set. When you chose custom setting, set a color below.'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#prefix' => '<div class="addclips-colors">',
'#suffix' => '</div>',
);
$form['addclips_colors']['addclips_colorset'] = array(
'#type' => 'select',
'#title' => t('Color Set'),
'#options' => array(
'#78BE44,#D1E9C0,#666666' => t('Green (Default)'),
'#FF4646,#FFACAC,#FFFFFF' => t('Red'),
'#0080FF,#7AB1F5,#FFFFFF' => t('Blue'),
'#FF6600,#FF9900,#FFFFFF' => t('Orange'),
'#999999,#F6F6F6,#666666' => t('Gray'),
'#000000,#333333,#ffffff' => t('Black'),
'custom' => t('Custom'),
),
'#default_value' => variable_get('addclips_colorset', '#2385c2,#5ab5ee,#494949'),
);
if (module_exists('colorpicker')) {
$form['addclips_colors']['addclips_colorpicker'] = array(
'#type' => 'colorpicker',
'#title' => t('Color picker'),
'#prefix' => '<div class="colorsettings-colorpicker">',
'#suffix' => '</div>',
);
$form['addclips_colors']['addclips_b_pickcolor'] = array(
'#type' => 'colorpicker_textfield',
'#title' => t('Border color'),
'#default_value' => variable_get('addclips_b_pickcolor', '#'),
'#colorpicker' => 'addclips_colorpicker',
'#maxlength' => 7,
);
$form['addclips_colors']['addclips_n_pickcolor'] = array(
'#type' => 'colorpicker_textfield',
'#title' => t('Background color'),
'#default_value' => variable_get('addclips_n_pickcolor', '#'),
'#colorpicker' => 'addclips_colorpicker',
'#maxlength' => 7,
);
$form['addclips_colors']['addclips_t_pickcolor'] = array(
'#type' => 'colorpicker_textfield',
'#title' => t('Text color'),
'#default_value' => variable_get('addclips_t_pickcolor', '#'),
'#colorpicker' => 'addclips_colorpicker',
'#maxlength' => 7,
);
}
else {
$form['addclips_colors']['addclips_b_color'] = array(
'#type' => 'textfield',
'#title' => t('Border color'),
'#default_value' => variable_get('addclips_b_color', ''),
'#maxlength' => 7,
'#size' => 15,
);
$form['addclips_colors']['addclips_n_color'] = array(
'#type' => 'textfield',
'#title' => t('Background color'),
'#default_value' => variable_get('addclips_n_color', ''),
'#maxlength' => 7,
'#size' => 15,
);
$form['addclips_colors']['addclips_t_color'] = array(
'#type' => 'textfield',
'#title' => t('Text color'),
'#default_value' => variable_get('addclips_t_color', ''),
'#maxlength' => 7,
'#size' => 15,
);
}
return system_settings_form($form);
}
/**
* Implementation of hook_link().
*/
function addclips_link($type, $node = NULL, $teaser = FALSE) {
$links = array();
if ($type == 'node' && variable_get('addclips_use','') == 1 && variable_get('addclips_id', '') && !in_array($node->type, variable_get('addclips_nodetypes_exclude', array()))) {
// Get values
global $base_url;
if (variable_get('addclips_object', 'page') == 'site') {
$addclips_url = $base_url;
$sitename = array(variable_get('site_name', 'Drupal'));
if (variable_get('site_slogan', '')) : $sitename[] = str_replace("'", "\'", variable_get('site_slogan', '')); endif;
$addclips_title = implode(' | ', $sitename);
}
else {
$addclips_url = $base_url . '/' . drupal_get_path_alias('node/' . $node->nid);
$addclips_title = str_replace("'", "\'", $node->title);
}
$addclips_id = variable_get('addclips_id', '');
$addclips_type = variable_get('addclips_type', 5);
$addclips_valign = variable_get('addclips_valign', 'middle');
$addclips_color = addclips_get_color();
// AddClops Codes (c) 2006-2008 AddClips
$addclips_code = '<!-- AddClips Code START -->' . "\n";
$addclips_code .= '<script type="text/javascript">' . "\n";
$addclips_code .= " AddClipsUrl = '" . $addclips_url . "';" . "\n";
$addclips_code .= " AddClipsTitle = '" . $addclips_title . "';" . "\n";
$addclips_code .= " AddClipsId = '" . $addclips_id . "';" . "\n";
$addclips_code .= " AddClipsBcolor ='" . $addclips_color['b'] . "';" . "\n";
$addclips_code .= " AddClipsNcolor ='" . $addclips_color['n'] . "';" . "\n";
$addclips_code .= " AddClipsTcolor ='" . $addclips_color['t'] . "';" . "\n";
$addclips_code .= " AddClipsType ='" . $addclips_type . "';" . "\n";
$addclips_code .= " AddClipsVerticalAlign ='" . $addclips_valign . "'; " . "\n";
$addclips_code .= '</script><script type="text/javascript" src="http://js.addclips.org/v2/addclips.js" charset="utf-8"></script>' . "\n";
$addclips_code .= '<!-- AddClips Code END -->';
if (variable_get('addclips_view', 'both') == 'both' || (variable_get('addclips_view', 'both') == 'node' && !$teaser) || (variable_get('addclips_view', 'both') == 'teaser' && $teaser)) {
$links['addclips'] = array(
'title' => $addclips_code,
'html' => TRUE,
);
}
}
return $links;
}
/**
* Helper function for hook_link().
*/
function addclips_get_color() {
$color['b'] = '#78BE44';
$color['n'] = '#D1E9C0';
$color['t'] = '#666666';
$colorset = variable_get('addclips_colorset', '#2385c2,#5ab5ee,#494949');
if ($colorset) {
if ($colorset == 'custom') {
if (module_exists('colorpicker')) {
$b_color = variable_get('addclips_b_pickcolor', '#');
$n_color = variable_get('addclips_n_pickcolor', '#');
$t_color = variable_get('addclips_t_pickcolor', '#');
if ($b_color && $b_color != '#') : $color['b'] = $b_color; endif;
if ($n_color && $n_color != '#') : $color['n'] = $n_color; endif;
if ($t_color && $t_color != '#') : $color['t'] = $t_color; endif;
}
else {
$b_color = variable_get('addclips_b_color', '');
$n_color = variable_get('addclips_n_color', '');
$t_color = variable_get('addclips_t_color', '');
if ($b_color) : $color['b'] = $b_color; endif;
if ($n_color) : $color['n'] = $n_color; endif;
if ($t_color) : $color['t'] = $t_color; endif;
}
}
else {
list($color['b'], $color['n'], $color['t']) = explode(',', $colorset);
}
}
return $color;
}

