1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Admin page callbacks for the Twitter Block module.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
a6e869e4
|
Assos Assos
|
/**
|
9 |
|
|
* Implements hook_admin_settings() for module settings configuration.
|
10 |
|
|
*/
|
11 |
|
|
function twitter_block_admin_settings_form($form, &$form_state) {
|
12 |
|
|
// Advanced feature configurations.
|
13 |
|
|
$form['advanced'] = array(
|
14 |
|
|
'#type' => 'fieldset',
|
15 |
|
|
'#title' => t('Advanced settings'),
|
16 |
|
|
'#collapsible' => TRUE,
|
17 |
|
|
'#collapsed' => TRUE,
|
18 |
|
|
);
|
19 |
|
|
|
20 |
|
|
$form['advanced']['twitter_block_cache'] = array(
|
21 |
|
|
'#type' => 'checkbox',
|
22 |
|
|
'#title' => t('Locally cache widget code'),
|
23 |
|
|
'#description' => t("If checked, the widget code is retrieved from Twitter and cached locally. It is updated daily from Twitter's servers to ensure updates to widget code are reflected in the local copy."),
|
24 |
|
|
'#default_value' => variable_get('twitter_block_cache', 0),
|
25 |
|
|
);
|
26 |
|
|
|
27 |
|
|
return system_settings_form($form);
|
28 |
|
|
}
|
29 |
|
|
|
30 |
85ad3d82
|
Assos Assos
|
/**
|
31 |
|
|
* Form constructor for the add block form.
|
32 |
|
|
*
|
33 |
|
|
* @see twitter_block_add_block_form_validate()
|
34 |
|
|
* @see twitter_block_add_block_form_submit()
|
35 |
|
|
* @ingroup forms
|
36 |
|
|
*/
|
37 |
|
|
function twitter_block_add_block_form($form, &$form_state) {
|
38 |
|
|
module_load_include('inc', 'block', 'block.admin');
|
39 |
|
|
$form = block_admin_configure($form, $form_state, 'twitter_block', NULL);
|
40 |
|
|
|
41 |
|
|
// Other modules should be able to use hook_form_block_add_block_form_alter()
|
42 |
66b5cbf6
|
Assos Assos
|
// to modify this form, so add a base form ID.
|
43 |
85ad3d82
|
Assos Assos
|
$form_state['build_info']['base_form_id'] = 'block_add_block_form';
|
44 |
|
|
|
45 |
|
|
// Prevent block_add_block_form_validate/submit() from being automatically
|
46 |
66b5cbf6
|
Assos Assos
|
// added because of the base form ID by providing these handlers manually.
|
47 |
85ad3d82
|
Assos Assos
|
$form['#validate'] = array('twitter_block_add_block_form_validate');
|
48 |
|
|
$form['#submit'] = array('twitter_block_add_block_form_submit');
|
49 |
|
|
|
50 |
|
|
return $form;
|
51 |
|
|
}
|
52 |
|
|
|
53 |
|
|
/**
|
54 |
|
|
* Form validation handler for twitter_block_add_block_form().
|
55 |
|
|
*
|
56 |
|
|
* @see twitter_block_add_block_form()
|
57 |
|
|
* @see twitter_block_add_block_form_submit()
|
58 |
|
|
*/
|
59 |
|
|
function twitter_block_add_block_form_validate($form, &$form_state) {
|
60 |
|
|
$unique_description = (bool) db_query_range('SELECT 1 FROM {twitter_block} WHERE info = :info', 0, 1, array(':info' => $form_state['values']['info']))->fetchField();
|
61 |
|
|
|
62 |
|
|
if (empty($form_state['values']['info']) || $unique_description) {
|
63 |
|
|
form_set_error('info', t('Ensure that each block description is unique.'));
|
64 |
|
|
}
|
65 |
|
|
|
66 |
|
|
$unique_widget_id = (bool) db_query_range('SELECT 1 FROM {twitter_block} WHERE widget_id = :widget_id', 0, 1, array(':widget_id' => $form_state['values']['widget_id']))->fetchField();
|
67 |
|
|
|
68 |
|
|
if (empty($form_state['values']['widget_id']) || $unique_widget_id) {
|
69 |
|
|
form_set_error('widget_id', t('Ensure that each block widget ID is unique.'));
|
70 |
|
|
}
|
71 |
|
|
}
|
72 |
|
|
|
73 |
|
|
/**
|
74 |
|
|
* Form submission handler for twitter_block_add_block_form().
|
75 |
|
|
*
|
76 |
|
|
* Saves the new custom Twitter block.
|
77 |
|
|
*
|
78 |
|
|
* @see twitter_block_add_block_form()
|
79 |
|
|
* @see twitter_block_add_block_form_validate()
|
80 |
|
|
*/
|
81 |
|
|
function twitter_block_add_block_form_submit($form, &$form_state) {
|
82 |
|
|
// The serialized 'data' column contains the timeline settings.
|
83 |
|
|
$data = array(
|
84 |
|
|
'theme' => $form_state['values']['theme'],
|
85 |
|
|
'link_color' => $form_state['values']['link_color'],
|
86 |
|
|
'width' => $form_state['values']['width'],
|
87 |
|
|
'height' => $form_state['values']['height'],
|
88 |
|
|
'chrome' => $form_state['values']['chrome'],
|
89 |
|
|
'border_color' => $form_state['values']['border_color'],
|
90 |
|
|
'language' => $form_state['values']['language'],
|
91 |
|
|
'tweet_limit' => $form_state['values']['tweet_limit'],
|
92 |
|
|
'related' => $form_state['values']['related'],
|
93 |
|
|
'polite' => $form_state['values']['polite'],
|
94 |
|
|
);
|
95 |
|
|
|
96 |
66b5cbf6
|
Assos Assos
|
// Save the block configuration.
|
97 |
85ad3d82
|
Assos Assos
|
$delta = db_insert('twitter_block')
|
98 |
|
|
->fields(array(
|
99 |
|
|
'info' => $form_state['values']['info'],
|
100 |
|
|
'widget_id' => $form_state['values']['widget_id'],
|
101 |
66b5cbf6
|
Assos Assos
|
'username' => $form_state['values']['username'],
|
102 |
85ad3d82
|
Assos Assos
|
'data' => serialize($data),
|
103 |
|
|
))
|
104 |
|
|
->execute();
|
105 |
|
|
|
106 |
66b5cbf6
|
Assos Assos
|
// Store block delta to allow other modules to work with new block.
|
107 |
85ad3d82
|
Assos Assos
|
$form_state['values']['delta'] = $delta;
|
108 |
|
|
|
109 |
66b5cbf6
|
Assos Assos
|
// Run the normal new block submission (borrowed from block_add_block_form_submit).
|
110 |
85ad3d82
|
Assos Assos
|
$query = db_insert('block')->fields(array('visibility', 'pages', 'custom', 'title', 'module', 'theme', 'status', 'weight', 'delta', 'cache'));
|
111 |
|
|
foreach (list_themes() as $key => $theme) {
|
112 |
|
|
if ($theme->status) {
|
113 |
|
|
$query->values(array(
|
114 |
|
|
'visibility' => (int) $form_state['values']['visibility'],
|
115 |
|
|
'pages' => trim($form_state['values']['pages']),
|
116 |
|
|
'custom' => (int) $form_state['values']['custom'],
|
117 |
|
|
'title' => $form_state['values']['title'],
|
118 |
|
|
'module' => $form_state['values']['module'],
|
119 |
|
|
'theme' => $theme->name,
|
120 |
|
|
'status' => 0,
|
121 |
|
|
'weight' => 0,
|
122 |
|
|
'delta' => $delta,
|
123 |
|
|
'cache' => DRUPAL_NO_CACHE,
|
124 |
|
|
));
|
125 |
|
|
}
|
126 |
|
|
}
|
127 |
|
|
$query->execute();
|
128 |
|
|
|
129 |
|
|
$query = db_insert('block_role')->fields(array('rid', 'module', 'delta'));
|
130 |
|
|
foreach (array_filter($form_state['values']['roles']) as $rid) {
|
131 |
|
|
$query->values(array(
|
132 |
|
|
'rid' => $rid,
|
133 |
|
|
'module' => $form_state['values']['module'],
|
134 |
|
|
'delta' => $delta,
|
135 |
|
|
));
|
136 |
|
|
}
|
137 |
|
|
$query->execute();
|
138 |
|
|
|
139 |
66b5cbf6
|
Assos Assos
|
// Store regions per theme for this block.
|
140 |
85ad3d82
|
Assos Assos
|
foreach ($form_state['values']['regions'] as $theme => $region) {
|
141 |
|
|
db_merge('block')
|
142 |
|
|
->key(array('theme' => $theme, 'delta' => $delta, 'module' => $form_state['values']['module']))
|
143 |
|
|
->fields(array(
|
144 |
|
|
'region' => ($region == BLOCK_REGION_NONE ? '' : $region),
|
145 |
|
|
'pages' => trim($form_state['values']['pages']),
|
146 |
|
|
'status' => (int) ($region != BLOCK_REGION_NONE),
|
147 |
|
|
))
|
148 |
|
|
->execute();
|
149 |
|
|
}
|
150 |
|
|
|
151 |
|
|
drupal_set_message(t('The block has been created.'));
|
152 |
|
|
cache_clear_all();
|
153 |
|
|
$form_state['redirect'] = 'admin/structure/block';
|
154 |
|
|
}
|
155 |
|
|
|
156 |
|
|
/**
|
157 |
|
|
* Form constructor for the custom Twitter block deletion form.
|
158 |
|
|
*
|
159 |
|
|
* @param $delta
|
160 |
|
|
* The unique ID of the block within the context of $module.
|
161 |
|
|
*
|
162 |
|
|
* @see twitter_block_delete_submit()
|
163 |
|
|
*/
|
164 |
|
|
function twitter_block_delete($form, &$form_state, $delta) {
|
165 |
|
|
$block = block_load('twitter_block', $delta);
|
166 |
|
|
$twitter_block = twitter_block_block_get($block->delta);
|
167 |
|
|
$form['info'] = array('#type' => 'hidden', '#value' => $twitter_block['info'] ? $twitter_block['info'] : $twitter_block['title']);
|
168 |
|
|
$form['bid'] = array('#type' => 'hidden', '#value' => $block->delta);
|
169 |
|
|
|
170 |
|
|
return confirm_form($form, t('Are you sure you want to delete the block %name?', array('%name' => $twitter_block['info'])), 'admin/structure/block', '', t('Delete'), t('Cancel'));
|
171 |
|
|
}
|
172 |
|
|
|
173 |
|
|
/**
|
174 |
|
|
* Form submission handler for twitter_block_delete().
|
175 |
|
|
*
|
176 |
|
|
* @see twitter_block_delete()
|
177 |
|
|
*/
|
178 |
|
|
function twitter_block_delete_submit($form, &$form_state) {
|
179 |
|
|
db_delete('twitter_block')
|
180 |
|
|
->condition('bid', $form_state['values']['bid'])
|
181 |
|
|
->execute();
|
182 |
|
|
db_delete('block')
|
183 |
|
|
->condition('module', 'twitter_block')
|
184 |
|
|
->condition('delta', $form_state['values']['bid'])
|
185 |
|
|
->execute();
|
186 |
|
|
db_delete('block_role')
|
187 |
|
|
->condition('module', 'twitter_block')
|
188 |
|
|
->condition('delta', $form_state['values']['bid'])
|
189 |
|
|
->execute();
|
190 |
|
|
drupal_set_message(t('The block %name has been removed.', array('%name' => $form_state['values']['info'])));
|
191 |
|
|
cache_clear_all();
|
192 |
|
|
$form_state['redirect'] = 'admin/structure/block';
|
193 |
|
|
return;
|
194 |
|
|
} |