/
tencent_weibo.module
executable file
·113 lines (100 loc) · 3.14 KB
/
tencent_weibo.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
<?php
// $Id$
/**
* Implementation of hook_meu()
*/
function tencent_weibo_menu() {
$items = array();
$items['tencent-weibo/callback'] = array(
'access callback' => TRUE,
'page callback' => 'tencent_weibo_callback',
'type' => MENU_CALLBACK,
'file' => 'tencent_weibo.pages.inc',
);
$items['tencent-weibo/login'] = array(
'access callback' => TRUE,
'page callback' => 'tencent_weibo_login',
'type' => MENU_CALLBACK,
'file' => 'tencent_weibo.pages.inc',
);
$items['user/register/tencent-weibo'] = array(
'access callback' => 'user_register_access',
'page callback' => 'drupal_get_form',
'page arguments' => array('user_register'),
'title' => 'Create Local Account',
'type' => MENU_CALLBACK,
'file' => 'tencent_weibo.pages.inc',
);
$items['user/login/tencent-weibo'] = array(
'access callback' => 'user_is_anonymous',
'page callback' => 'drupal_get_form',
'page arguments' => array('user_login'),
'title' => t('Login'),
'type' => MENU_CALLBACK,
'file' => 'tencent_weibo.pages.inc',
);
$items['admin/settings/tencent-weibo'] = array(
'title' => 'Weibo setup',
'description' => 'Tencent Weibo module settings',
'page callback' => 'drupal_get_form',
'page arguments' => array('tencent_weibo_admin_form'),
'access arguments' => array('administer site configuration'),
'file' => 'tencent_weibo.admin.inc'
);
/*$items['admin/settings/tencent-weibo/default'] = array(
'title' => 'Tencent Weibo',
'type' => MENU_DEFAULT_LOCAL_TASK
);*/
return $items;
}
/**
* Implementation of hook_perm()
*/
function tencent_weibo_perm() {
return array('add qq weibo accounts');
}
/**
* Implementation of hook_cron()
*
*/
function tencent_weibo_cron() {
}
/**
* Implementation of hook_form_FORM_ID_alter
*/
function tencent_weibo_form_user_login_alter(&$form, $form_state) {
if(variable_get('sina_weibo_api_key', '') && variable_get('sina_weibo_api_secret', '')) {
$form['tencent_weibo_signin'] = array(
'#type' => 'markup',
'#value' => theme_tencent_weibo_signin()
);
}
}
/**
* Implementation of hook_form_FORM_ID_alter
*/
function tencent_weibo_form_user_register_alter(&$form, $form_state) {
if(arg(0) == 'user' && arg(1) == 'register' && arg(2) == 'tencent-weibo') {
$form['name']['#default_value'] = $_SESSION['tencent_weibo_token']['screen_name'];
$form['#submit'][] = 'tencent_weibo_register_submit';
}
}
function theme_tencent_weibo_signin() {
return '<div class="tencent-weibo-signin">' . l(theme('image', drupal_get_path('module', 'tencent_weibo') . '/images/24.png', '', '', array(), FALSE), 'tencent-weibo/login', array('html' => TRUE)) . '</div>';
}
/**
* Implementation of hook_user
*/
function tencent_weibo_user($op, &$edit, &$account, $category = NULL) {
switch ($op) {
case 'load':
$tencent_weibo = db_fetch_array(db_query('SELECT * FROM {weibo_tencent_users} WHERE uid = %d', $account->uid));
if($tencent_weibo) {
$account->tencent_weibo = $tencent_weibo;
}
break;
case 'delete':
db_query('DELETE FROM {weibo_tencent_users} WHERE uid=%d', $account->uid);
break;
}
}