-
Notifications
You must be signed in to change notification settings - Fork 0
/
owstech_share.module
223 lines (188 loc) · 7.02 KB
/
owstech_share.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
<?php
/**
* @file
* General trackerless share plugin for Drupal
* Currently only supports facebook, twitter, gplus, and reddit, this can grow rather easily.
* For facebook preview information one must populate the open-graph title, description and image fields,
* The meta_data module can supply those http://drupal.org/project/metatag
*/
/**
* Implements hook_help().
*/
function owstech_share($path, $arg) {
if ($path == 'admin/help#owstech_share') {
return t('Help for the OWSTech Share module!');
}
}
/**
* Implements hook_menu().
*
* Basic admin menu for this module.
*/
function owstech_share_menu() {
$items['admin/config/user-interface/owstech_share'] = array(
'title' => 'OWSTech Share',
'description' => '',
'page callback' => 'drupal_get_form',
'page arguments' => array( 'owstech_share_admin_form' ),
'access arguments' => array('administer site configuration'),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
/**
* Form builder: Build the settings form for this module.
*/
function owstech_share_admin_form( $form, &$form_state ) {
/* Setup groups */
$form['general'] = array(
'#type' => 'fieldset',
'#title' => t('General'),
'#tree' => FALSE,
'#weight' => 0,
);
$form['facebook_fields'] = array(
'#type' => 'fieldset',
'#title' => t('Facebook settings'),
'#tree' => FALSE,
'#weight' => 1,
);
$form['twitter_fields'] = array(
'#type' => 'fieldset',
'#title' => t('Twitter settings'),
'#tree' => FALSE,
'#weight' => 2,
);
$form['googleplus_fields'] = array(
'#type' => 'fieldset',
'#title' => t('Google+ settings'),
'#tree' => FALSE,
'#weight' => 3,
);
$form['reddit_fields'] = array(
'#type' => 'fieldset',
'#title' => t('Reddit settings'),
'#tree' => FALSE,
'#weight' => 4,
);
/* Fields */
$form['general']['owstech_share_actuator_text'] = array(
'#type' => 'textfield',
'#title' => t('Share widget label'),
'#default_value' => variable_get( 'owstech_share_actuator_text', t('Share +') ),
'#description' => t('What to label the share widget actuator.'),
);
$form['facebook_fields']['owstech_share_include_facebook'] = array(
'#type' => 'checkbox',
'#title' => t('Facebook'),
'#default_value' => variable_get( 'owstech_share_include_facebook', TRUE ),
'#description' => t('Include Facebook as a share point.'),
);
$form['twitter_fields']['owstech_share_include_twitter'] = array(
'#type' => 'checkbox',
'#title' => t('Twitter'),
'#description' => t('Include Twitter as a share point.'),
'#default_value' => variable_get( 'owstech_share_include_twitter', TRUE ),
);
$form['twitter_fields']['owstech_share_tweet_text'] = array(
'#type' => 'textfield',
'#title' => t('Tweet text'),
'#default_value' => variable_get( 'owstech_share_tweet_text', t('[node:title]' ) ),
);
$form['googleplus_fields']['owstech_share_include_googleplus'] = array(
'#type' => 'checkbox',
'#title' => t('Google +'),
'#description' => t('Include Google + as a share point.'),
'#default_value' => variable_get( 'owstech_share_include_googleplus', TRUE ),
);
$form['reddit_fields']['owstech_share_include_reddit'] = array(
'#type' => 'checkbox',
'#title' => t('Reddit'),
'#description' => t('Include Reddit as a share point.'),
'#default_value' => variable_get('owstech_share_include_reddit', TRUE),
);
$form['reddit_fields']['owstech_share_reddit_title'] = array(
'#type' => 'textfield',
'#title' => t('Reddit entry title'),
'#description' => t('Title for Reddit share box.'),
'#default_value' => variable_get( 'owstech_share_reddit_title', t('[node:title]' ) ),
);
return system_settings_form( $form );
}
/**
* Implements hook_block_info().
*/
function owstech_share_block_info() {
$blocks = array();
$blocks['owstech-share'] = array(
'info' => t('OWSTechShare, a tracking-free, spiffy social media share that aims for simplicity and wont clutter your site with corporate logos.'),
);
return $blocks;
}
/**
* Implements hook_block_view().
*/
function owstech_share_block_view( $which_block = '' ) {
$variables = array( "hi" => "hihi" );
switch ( $which_block ) {
case 'owstech-share':
$modpath = drupal_get_path('module', 'owstech_share');
drupal_add_js( $modpath . '/js/owstech_share.js' );
drupal_add_css( $modpath . '/css/owstech_share.css' );
$block['content'] = theme('owstech_share', $variables );
break;
}
return $block;
}
/**
* Implements hook_theme().
*
* Defines theme for blocks, in this case owste-share.
* template = owstech_share.tpl.php
*/
function owstech_share_theme() {
$theme = array();
$theme['owstech_share'] = array(
'template' => 'owstech-share-drawer',
'path' => drupal_get_path('module', 'owstech_share') . '/templates/',
);
return $theme;
}
/**
* Implements template_preprocess_hook().
*
* Let's juggle some variables
*/
function template_preprocess_owstech_share( &$variables ) {
global $language, $base_url;
$node = menu_get_object();
$nid = $node->nid;
$t_vars = array(
"@page_title@" => $node->title,
);
$current_path = $base_url . '/' . drupal_get_path_alias( current_path(), $language->language );
$variables['node_title'] = $node->title;
$variables['owstech_share_actuator_text'] = variable_get('owstech_share_actuator_text');
$variables['owstech_share_include_facebook'] = variable_get('owstech_share_include_facebook');
$variables['owstech_share_include_twitter'] = variable_get('owstech_share_include_twitter');
$variables['owstech_share_include_googleplus'] = variable_get('owstech_share_include_googleplus');
$variables['owstech_share_include_reddit'] = variable_get('owstech_share_include_reddit');
$variables['owstech_share_tweet_text'] = token_replace( variable_get('owstech_share_tweet_text'), array( 'node' => $node ) );
$variables['owstech_share_reddit_title'] = token_replace( variable_get('owstech_share_reddit_title'), array( 'node' => $node ) );
if ( $variables['owstech_share_include_facebook'] ) {
$variables['share_cta_fb'] = t( "Share @page_title@ on Facebook", $t_vars );
$variables['share_url_fb'] = 'http://www.facebook.com/share.php?u=' . $current_path;
}
if ( $variables['owstech_share_include_twitter']) {
$variables['share_cta_twitter'] = t( "Tweet @page_title@!", $t_vars );
$variables['share_url_twitter'] = 'http://twitter.com/intent/tweet?url=' . drupal_encode_path( $current_path ) . '&text=' . $variables['owstech_share_tweet_text'];
}
if ( $variables['owstech_share_include_googleplus'] ) {
$variables['share_cta_googleplus'] = t( "Share @page_title@ on Google +", $t_vars );
$variables['share_url_googleplus'] = 'https://plus.google.com/share?url=' . $current_path;
}
if ( $variables['owstech_share_include_reddit'] ) {
$variables['share_cta_reddit'] = t( "Reddit @page_title@!", $t_vars );
$variables['share_url_reddit'] = 'http://www.reddit.com/submit?url=' . $current_path . "&title=" . $variables['owstech_share_reddit_title'];
}
}