-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshare_pin.module
222 lines (197 loc) · 6.04 KB
/
share_pin.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
<?php
//path for the form "Add to Favorite"
define('PATH_FAVORITE_FORM', 'user/new-favorite/add');
//path for the page "Add to Share"
define('PATH_SHARE_FORM', 'user/share/');
/**
* Implementation of hook_access().
* @return
* TRUE if the operation may be performed, FALSE otherwise.
*/
function share_pin_access($sid = NULL) {
global $user;
$current_path = current_path();
if ($user->uid != FALSE) {
return TRUE;
}
if (user_is_anonymous()) {
switch ($current_path) {
case PATH_FAVORITE_FORM:
return TRUE;
case 'user/favorite/'.$user->uid.'/save':
return TRUE;
case PATH_SHARE_FORM.$sid:
return TRUE;
}
}
}
/**
* Implementation of hook_menu().
*/
function share_pin_menu() {
$items = array();
/* $items['user/favorite/add'] = array(
'title' => t('Add to Favorites'),
'page callback' => 'share_pin_favorite_add',
'page arguments' => array('share_element'),
'access callback' => 'share_pin_access',
'access arguments' => array('create', 'share_element'),
//'theme callback' => 'share_pin_return_theme',
'type' => MENU_CALLBACK,
'file' => 'node.pages.inc',
'file path' => 'modules/node'
);*/
$items['user/favorite/%node/edit'] = array(
'title' => t('Edit favorite'),
'page callback' => 'node_page_edit',
'page arguments' => array(2),
'access callback' => 'node_access',
'access arguments' => array('update', 2),
'type' => MENU_CALLBACK,
'file' => 'node.pages.inc',
'file path' => 'modules/node'
);
$items['user/favorite/%/save'] = array(
'title' => t('Sending content to katmary'),
'page callback' => 'drupal_get_form',
'page arguments' => array('share_pin_sending_data_form', 2),
'access callback' => 'share_pin_access',
'type' => MENU_CALLBACK,
'file' => 'includes/share_pin_sending_data.pages.inc',
);
$items['user/new-favorite/add'] = array(
'title' => t('Add to Favorites'),
'page callback' => 'share_page_add',
'page arguments' => array('share_form_add'),
'access callback' => 'share_pin_access',
'type' => MENU_CALLBACK,
'file' => 'includes/share.form.inc',
);
$items['user/share/%'] = array(
'title' => t('Share'),
'page callback' => 'share_page_add',
'page arguments' => array('share_form_add', 2),
'access callback' => 'share_pin_access',
'access arguments' => array(2),
'type' => MENU_CALLBACK,
'file' => 'includes/share.form.inc',
);
return $items;
}
/**
* Implements hook_form_alter().
*/
function share_pin_form_alter(&$form, &$form_state, $form_id) {
global $user;
$current_path = current_path();
$sid = arg(2);
//dsm($current_path);
/* if($form_id = 'statuses_box'){
unset($form['fbsmp']['video_icon'], $form['fbsmp']['slideshare_icon']);
}*/
if ($form_id == 'share_form_add') {
drupal_set_title(t('Add to Favorites'));
drupal_add_css(drupal_get_path('module', 'share_pin') . '/css/share_pin.form.css');
if ($current_path == PATH_FAVORITE_FORM) {
//set submit
$form['#submit'][] = 'share_pin_form_submit';
$form['#theme'] = array('share_pin_form');
}
if ($current_path == PATH_SHARE_FORM . $sid) {
//set submit
// $form['#submit'][] = 'share_pin_form_submit';
// $form['#theme'] = array('share_pin_form');
}
}
if ($form_id == 'user_login') {
drupal_set_title(t('Login in'));
$form['#submit'][] = 'share_pin_user_login_form_submit';
}
}
/**
* Implementation of hook_node_submit()
*/
function share_pin_form_submit($form, &$form_state) {
//dsm($form_state);
global $user;
if (arg(0) == 'user' && arg(1) == 'new-favorite' && arg(2) == 'add') {
$path = "user/favorite/{$user->uid}/save";
$_GET['destination'] = $path;
}
}
/**
* Implementation of hook_node_submit()
*/
function share_pin_user_login_form_submit($form, &$form_state) {
//set destination after login in
$path = $form['#action'];
$_GET['destination'] = $path;
}
/**
* Implementation of hook_block_info
*/
function share_pin_block_info() {
return array(
'share_pin_block' => array(
'info' => t('Share pin block'),
'status' => TRUE,
'region' => 'sidebar_first',
),
);
}
/**
* Implementation of hook_block_view
*/
function share_pin_block_view($delta = '') {
if ($delta == 'share_pin_block') {
return array(
'subject' => t('Share pin'),
'content' => array('#markup' => share_pin_block())
);
}
}
/**
* Return featured blogger block content.
*/
function share_pin_block() {
$output = '<a class="settings" name="Katmary Pin" title="Katmary Pin" onclick="alert(\'' . t('Please move it to the bookmarks bar') . '\'); return false;" href="javascript:void((function(){var e=document.createElement(\'script\');e.setAttribute(\'type\',\'text/javascript\');e.setAttribute(\'charset\',\'UTF-8\');e.setAttribute(\'src\',\'http://'.$_SERVER["SERVER_NAME"].'/'.drupal_get_path('module', 'share_pin').'/js/getjsforadd.js?r=\'+Math.random()*99999999);document.body.appendChild(e)})());">
<span class="pin-title-btn">Katmary Pin</span>
</a>';
return $output;
}
/**
* Implementation of hook_theme()
*/
function share_pin_theme($existing, $type, $theme, $path) {
return array(
'share_pin_form' => array(
'path' => drupal_get_path('module', 'share_pin') . '/templates',
'template' => 'share_pin_form',
'arguments' => array('form' => NULL),
'render element' => 'form',
),
);
}
/**
* Implements hook_preprocess_page().
*/
function share_pin_preprocess(&$vars) {
// /dsm($vars);
if (arg(0) == 'user' && (arg(1) == 'favorite' || arg(1) == 'new-favorite') && (arg(2) == 'add'||arg(3) == 'save')) {
unset(
$vars['page']['header'],
$vars['page']['page_top'],
$vars['page']['#type']
);
$vars['logo'] = '';
$vars['site_name'] = '';
$vars['main_menu'] = '';
$vars['secondary_menu'] = '';
$vars['page']['sidebar_first'] = '';
$vars['page']['sidebar_second'] = '';
$vars['page']['page_bottom'] = '';
$vars['page']['footer'] = '';
$vars['tabs'] = '';
// dsm($vars);
}
}