-
Notifications
You must be signed in to change notification settings - Fork 0
/
easy_hatena.module
125 lines (119 loc) · 3.79 KB
/
easy_hatena.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
/**
* @file
* Easy Hatena module.
*/
/**
* Implements hook_menu().
*/
function easy_hatena_menu() {
$items = array();
$items['admin/config/content/easy_social/widget-extra/hatena'] = array(
'title' => 'Hatena',
'description' => 'Extra settings for Hatena Bookmark',
'page callback' => 'drupal_get_form',
'page arguments' => array('_easy_social_admin_config_extra_hatena'),
'access arguments' => array('administer easy social'),
'type' => MENU_LOCAL_TASK,
);
return $items;
}
/**
* Implements hook_easy_social_widget().
*/
function easy_hatena_easy_social_widget() {
return array(
'hatena' => array(
'name' => 'Hatena',
'markup' => '_easy_hatena_custom_share_button_markup',
'scripts' => array(
array(
'path' => '//b.st-hatena.com/js/bookmark_button.js',
'type' => 'external',
),
),
'styles' => array(
array(
'path' => drupal_get_path('module', 'easy_hatena') . '/css/easy_hatena.css',
'type' => 'module',
),
),
),
);
}
/**
* Generate the needed markup for the Hatena bookmark.
*
* @param $url The url to be shared
* @param $type Generate horizontal or vertical widgets
* @param $title The title to be shared
* @param $lang The language of the facebook button
* @return string the html markup
*/
function _easy_hatena_custom_share_button_markup($url, $type, $title = NULL, $lang = "ja") {
$layout = variable_get_value('easy_social_hatena_layout');
$lang = variable_get_value('easy_social_hatena_lang');
if ($type == EASY_SOCIAL_WIDGET_VERTICAL && $layout == 'standard-balloon') {
$bookmark_layout = 'vertical-balloon';
}
else {
$bookmark_layout = $layout;
}
$markup = <<<HATENA
<a href="{$url}" class="hatena-bookmark-button" data-hatena-bookmark-title="{$title}" data-hatena-bookmark-layout="{$bookmark_layout}" data-hatena-bookmark-lang="{$lang}" title="この記事をはてなブックマークに追加">
<img src="//b.st-hatena.com/images/entry-button/button-only@2x.png" alt="このエントリーをはてなブックマークに追加" width="20" height="20" style="border: none;" />
</a>
HATENA;
return $markup;
}
/**
* Implements hook_variable_info().
*/
function easy_hatena_variable_info() {
$variables = array();
$variables['easy_social_hatena_layout'] = array(
'title' => t("Easy Social Global Hatena Type of Layouts option"),
'default' => 'simple',
'group' => 'easy_social',
'token' => FALSE,
);
$variables['easy_social_hatena_lang'] = array(
'title' => t("Easy Social Global Hatena language option"),
'default' => 'ja',
'group' => 'easy_social',
'token' => FALSE,
);
return $variables;
}
/**
* Implements the settings form callback.
*/
function _easy_social_admin_config_extra_hatena() {
$form = array();
$form['easy_social_hatena_title'] = array(
'#markup' => '<h4>' . t('Hatena widget settings') . '</h4>',
);
$form['easy_social_hatena_info'] = array(
'#markup' => t('For more information check out the official Hatena bookmark widget <a href="!link" target="_blank">documentation</a>.',
array('!link' => 'http://b.hatena.ne.jp/guide/bbutton')),
);
$form['easy_social_hatena_layout'] = array(
'#type' => 'select',
'#title' => t("Type of layouts"),
'#default_value' => variable_get_value('easy_social_hatena_layout'),
'#options' => array(
'standard-noballoon' => t('Standard button'),
'standard-balloon' => t('Standard button with balloon'),
),
);
$form['easy_social_hatena_lang'] = array(
'#type' => 'select',
'#title' => t("Language"),
'#default_value' => variable_get_value('easy_social_hatena_lang'),
'#options' => array(
'ja' => t('Japanese'),
'en' => t('English')
),
);
return system_settings_form($form);
}