Révision 66b5cbf6
Ajouté par Assos Assos il y a presque 10 ans
drupal7/sites/all/modules/captcha/captcha.admin.inc | ||
---|---|---|
106 | 106 |
'#options' => $captcha_type_options, |
107 | 107 |
); |
108 | 108 |
|
109 |
// Checkbox to add default CAPTCHA to all non listed forms as well. |
|
110 |
$form['captcha_form_protection']['captcha_default_challenge_on_nonlisted_forms'] = array( |
|
111 |
'#type' => 'checkbox', |
|
112 |
'#title' => t('Default challenge on non-listed forms.'), |
|
113 |
'#default_value' => variable_get('captcha_default_challenge_on_nonlisted_forms', FALSE), |
|
114 |
'#description' => t('Normally, no challenge is added to forms that are not listed above. Enabling this option will add the default challenge instead.'), |
|
115 |
); |
|
116 |
|
|
109 | 117 |
// Field for the CAPTCHA administration mode. |
110 | 118 |
$form['captcha_form_protection']['captcha_administration_mode'] = array( |
111 | 119 |
'#type' => 'checkbox', |
... | ... | |
272 | 280 |
variable_set('captcha_allow_on_admin_pages', $form_state['values']['captcha_allow_on_admin_pages']); |
273 | 281 |
|
274 | 282 |
variable_set('captcha_default_challenge', $form_state['values']['captcha_default_challenge']); |
283 |
variable_set('captcha_default_challenge_on_nonlisted_forms', $form_state['values']['captcha_default_challenge_on_nonlisted_forms']); |
|
275 | 284 |
|
276 | 285 |
// Process CAPTCHA points |
277 | 286 |
if (isset($form_state['values']['captcha_form_id_overview']['captcha_captcha_points'])) { |
drupal7/sites/all/modules/captcha/captcha.inc | ||
---|---|---|
69 | 69 |
* or in the form 'captcha/Math'. |
70 | 70 |
*/ |
71 | 71 |
function captcha_get_form_id_setting($form_id, $symbolic=FALSE) { |
72 |
// Fetch setting from database. |
|
72 | 73 |
$result = db_query("SELECT module, captcha_type FROM {captcha_points} WHERE form_id = :form_id", |
73 | 74 |
array(':form_id' => $form_id)); |
74 | 75 |
$captcha_point = $result->fetchObject(); |
76 |
|
|
77 |
// If no setting is available in database for the given form, |
|
78 |
// but 'captcha_default_challenge_on_nonlisted_forms' is enabled, pick the default type anyway |
|
79 |
if (!$captcha_point && variable_get('captcha_default_challenge_on_nonlisted_forms', FALSE)) |
|
80 |
{ |
|
81 |
$captcha_point = (object) array('captcha_type' => 'default'); |
|
82 |
} |
|
83 |
|
|
84 |
// Handle (default) settings and symbolic mode. |
|
75 | 85 |
if (!$captcha_point) { |
76 | 86 |
$captcha_point = NULL; |
77 | 87 |
} |
drupal7/sites/all/modules/captcha/captcha.info | ||
---|---|---|
10 | 10 |
files[] = captcha.install |
11 | 11 |
files[] = captcha.test |
12 | 12 |
|
13 |
; Information added by drupal.org packaging script on 2013-06-25
|
|
14 |
version = "7.x-1.0"
|
|
13 |
; Information added by Drupal.org packaging script on 2014-07-06
|
|
14 |
version = "7.x-1.1"
|
|
15 | 15 |
core = "7.x" |
16 | 16 |
project = "captcha" |
17 |
datestamp = "1372203950"
|
|
17 |
datestamp = "1404666828"
|
|
18 | 18 |
|
drupal7/sites/all/modules/captcha/captcha.install | ||
---|---|---|
263 | 263 |
return $items; |
264 | 264 |
} |
265 | 265 |
|
266 |
|
|
267 | 266 |
/** |
268 | 267 |
* Implementation of hook_update_N() |
269 | 268 |
* Add a CAPTCHA token column to captcha_sessions table. |
... | ... | |
274 | 273 |
return $ret; |
275 | 274 |
} |
276 | 275 |
|
277 |
|
|
278 |
|
|
279 | 276 |
/** |
280 | 277 |
* Implementation of hook_update_N() |
281 | 278 |
* Rename the type field to captcha_type in captcha_points. |
... | ... | |
286 | 283 |
return $ret; |
287 | 284 |
} |
288 | 285 |
|
289 |
|
|
290 | 286 |
/** |
291 | 287 |
* Migrate form configuration for changed form ids in Drupal 7. |
292 | 288 |
*/ |
drupal7/sites/all/modules/captcha/captcha.module | ||
---|---|---|
6 | 6 |
* administrators can add a CAPTCHA to desired forms that users without |
7 | 7 |
* the 'skip CAPTCHA' permission (typically anonymous visitors) have |
8 | 8 |
* to solve. |
9 |
* |
|
10 | 9 |
*/ |
11 | 10 |
|
12 | 11 |
/** |
... | ... | |
216 | 215 |
'#value' => $captcha_sid, |
217 | 216 |
); |
218 | 217 |
|
219 |
// Additional one time CAPTCHA token: store in database and send with form. |
|
220 |
$captcha_token = md5(mt_rand()); |
|
221 |
db_update('captcha_sessions') |
|
222 |
->fields(array('token' => $captcha_token)) |
|
218 |
$captcha_token = db_select('captcha_sessions', 'c') |
|
219 |
->fields('c', array('token')) |
|
223 | 220 |
->condition('csid', $captcha_sid) |
224 |
->execute(); |
|
221 |
->execute() |
|
222 |
->fetchField(); |
|
223 |
if (!isset($captcha_token) && !$form_state['submitted']) { |
|
224 |
// Additional one-time CAPTCHA token: store in database and send with form. |
|
225 |
$captcha_token = md5(mt_rand()); |
|
226 |
db_update('captcha_sessions') |
|
227 |
->fields(array('token' => $captcha_token)) |
|
228 |
->condition('csid', $captcha_sid) |
|
229 |
->execute(); |
|
230 |
} |
|
231 |
|
|
225 | 232 |
$element['captcha_token'] = array( |
226 | 233 |
'#type' => 'hidden', |
227 | 234 |
'#value' => $captcha_token, |
... | ... | |
349 | 356 |
_captcha_insert_captcha_element($form, $captcha_placement, $captcha_element); |
350 | 357 |
} |
351 | 358 |
} |
352 |
else if (
|
|
353 |
variable_get('captcha_administration_mode', FALSE) |
|
354 |
&& user_access('administer CAPTCHA settings') |
|
355 |
&& (arg(0) != 'admin' || variable_get('captcha_allow_on_admin_pages', FALSE)) |
|
359 |
elseif ( |
|
360 |
variable_get('captcha_administration_mode', FALSE)
|
|
361 |
&& user_access('administer CAPTCHA settings')
|
|
362 |
&& (arg(0) != 'admin' || variable_get('captcha_allow_on_admin_pages', FALSE))
|
|
356 | 363 |
) { |
357 | 364 |
// Add CAPTCHA administration tools. |
358 | 365 |
module_load_include('inc', 'captcha'); |
drupal7/sites/all/modules/captcha/captcha_api.txt | ||
---|---|---|
1 |
|
|
2 | 1 |
This documentation is for developers that want to implement their own |
3 | 2 |
challenge type and integrate it with the base CAPTCHA module. |
4 | 3 |
|
drupal7/sites/all/modules/captcha/image_captcha/image_captcha.info | ||
---|---|---|
10 | 10 |
files[] = image_captcha.admin.inc |
11 | 11 |
files[] = image_captcha.user.inc |
12 | 12 |
|
13 |
; Information added by drupal.org packaging script on 2013-06-25
|
|
14 |
version = "7.x-1.0"
|
|
13 |
; Information added by Drupal.org packaging script on 2014-07-06
|
|
14 |
version = "7.x-1.1"
|
|
15 | 15 |
core = "7.x" |
16 | 16 |
project = "captcha" |
17 |
datestamp = "1372203950"
|
|
17 |
datestamp = "1404666828"
|
|
18 | 18 |
|
drupal7/sites/all/modules/captcha/image_captcha/image_captcha.user.inc | ||
---|---|---|
29 | 29 |
|
30 | 30 |
// Only generate captcha if code exists in the session. |
31 | 31 |
if ($code !== FALSE) { |
32 |
// Seed the random generators used for image CAPTCHA distortion based on session and code |
|
33 |
// to counter attacks that re-request the same challenge and pick the simplest image one or combine info. |
|
34 |
$seed = hexdec(substr(md5($captcha_sid . $code), 0, 8)); |
|
35 |
srand($seed); |
|
36 |
mt_srand($seed); |
|
32 | 37 |
// generate the image |
33 | 38 |
$image = @_image_captcha_generate_image($code); |
34 | 39 |
// check of generation was successful |
... | ... | |
124 | 129 |
$distortion_amplitude = .25 * $font_size * variable_get('image_captcha_distortion_amplitude', 0) / 10.0; |
125 | 130 |
if ($distortion_amplitude > 1) { |
126 | 131 |
// distortion parameters |
127 |
$wavelength_xr = (2+3*lcg_value())*$font_size;
|
|
128 |
$wavelength_yr = (2+3*lcg_value())*$font_size;
|
|
132 |
$wavelength_xr = (2 + 3 * mt_rand(0, 1000) / 1000) * $font_size;
|
|
133 |
$wavelength_yr = (2 + 3 * mt_rand(0, 1000) / 1000) * $font_size;
|
|
129 | 134 |
$freq_xr = 2 * 3.141592 / $wavelength_xr; |
130 | 135 |
$freq_yr = 2 * 3.141592 / $wavelength_yr; |
131 |
$wavelength_xt = (2+3*lcg_value())*$font_size;
|
|
132 |
$wavelength_yt = (2+3*lcg_value())*$font_size;
|
|
136 |
$wavelength_xt = (2 + 3 * mt_rand(0, 1000) / 1000) * $font_size;
|
|
137 |
$wavelength_yt = (2 + 3 * mt_rand(0, 1000) / 1000) * $font_size;
|
|
133 | 138 |
$freq_xt = 2 * 3.141592 / $wavelength_xt; |
134 | 139 |
$freq_yt = 2 * 3.141592 / $wavelength_yt; |
135 | 140 |
|
drupal7/sites/all/modules/twitter_block/readme.txt | ||
---|---|---|
6 | 6 |
* Installation |
7 | 7 |
* Permissions |
8 | 8 |
* Usage |
9 |
* Theming |
|
9 | 10 |
|
10 | 11 |
INTRODUCTION |
11 | 12 |
------------ |
... | ... | |
64 | 65 |
should be in the form of https://twitter.com/settings/widgets/WIDGET_ID/edit) |
65 | 66 |
or by looking at the widget's embed code (look for |
66 | 67 |
data-widget-id="WIDGET_ID"). |
68 |
|
|
69 |
Theming |
|
70 |
------- |
|
71 |
|
|
72 |
Embedded Timelines offer a number of customization options such as theme, layout |
|
73 |
and border color but, due to the way embedded timelines are implemented, custom |
|
74 |
theming using CSS can be difficult. |
|
75 |
|
|
76 |
To add custom CSS to embedded timelines check out the |
|
77 |
(http://github.com/kevinburke/customize-twitter-1.1) Customize Twitter project. |
drupal7/sites/all/modules/twitter_block/tests/twitter_block.test | ||
---|---|---|
49 | 49 |
$twitter_block['info'] = $this->randomName(8); |
50 | 50 |
$twitter_block['title'] = $this->randomName(8); |
51 | 51 |
$twitter_block['widget_id'] = $this->randomName(8); |
52 |
$twitter_block['username'] = $this->randomName(8); |
|
52 | 53 |
$this->drupalPost('admin/structure/block/add-twitter-block', $twitter_block, t('Save block')); |
53 | 54 |
|
54 | 55 |
// Confirm that the custom Twitter block has been created, and then query the created bid. |
drupal7/sites/all/modules/twitter_block/twitter_block.admin.inc | ||
---|---|---|
17 | 17 |
$form = block_admin_configure($form, $form_state, 'twitter_block', NULL); |
18 | 18 |
|
19 | 19 |
// Other modules should be able to use hook_form_block_add_block_form_alter() |
20 |
// to modify this form, so add a base form ID |
|
20 |
// to modify this form, so add a base form ID.
|
|
21 | 21 |
$form_state['build_info']['base_form_id'] = 'block_add_block_form'; |
22 | 22 |
|
23 | 23 |
// Prevent block_add_block_form_validate/submit() from being automatically |
24 |
// added because of the base form ID by providing these handlers manually |
|
24 |
// added because of the base form ID by providing these handlers manually.
|
|
25 | 25 |
$form['#validate'] = array('twitter_block_add_block_form_validate'); |
26 | 26 |
$form['#submit'] = array('twitter_block_add_block_form_submit'); |
27 | 27 |
|
... | ... | |
71 | 71 |
'polite' => $form_state['values']['polite'], |
72 | 72 |
); |
73 | 73 |
|
74 |
// Save the block configuration |
|
74 |
// Save the block configuration.
|
|
75 | 75 |
$delta = db_insert('twitter_block') |
76 | 76 |
->fields(array( |
77 | 77 |
'info' => $form_state['values']['info'], |
78 | 78 |
'widget_id' => $form_state['values']['widget_id'], |
79 |
'username' => $form_state['values']['username'], |
|
79 | 80 |
'data' => serialize($data), |
80 | 81 |
)) |
81 | 82 |
->execute(); |
82 | 83 |
|
83 |
// Store block delta to allow other modules to work with new block |
|
84 |
// Store block delta to allow other modules to work with new block.
|
|
84 | 85 |
$form_state['values']['delta'] = $delta; |
85 | 86 |
|
86 |
// Run the normal new block submission (borrowed from block_add_block_form_submit) |
|
87 |
// Run the normal new block submission (borrowed from block_add_block_form_submit).
|
|
87 | 88 |
$query = db_insert('block')->fields(array('visibility', 'pages', 'custom', 'title', 'module', 'theme', 'status', 'weight', 'delta', 'cache')); |
88 | 89 |
foreach (list_themes() as $key => $theme) { |
89 | 90 |
if ($theme->status) { |
... | ... | |
113 | 114 |
} |
114 | 115 |
$query->execute(); |
115 | 116 |
|
116 |
// Store regions per theme for this block |
|
117 |
// Store regions per theme for this block.
|
|
117 | 118 |
foreach ($form_state['values']['regions'] as $theme => $region) { |
118 | 119 |
db_merge('block') |
119 | 120 |
->key(array('theme' => $theme, 'delta' => $delta, 'module' => $form_state['values']['module'])) |
drupal7/sites/all/modules/twitter_block/twitter_block.info | ||
---|---|---|
8 | 8 |
|
9 | 9 |
dependencies[] = block |
10 | 10 |
|
11 |
; Information added by drupal.org packaging script on 2013-07-11
|
|
12 |
version = "7.x-2.1"
|
|
11 |
; Information added by Drupal.org packaging script on 2014-07-09
|
|
12 |
version = "7.x-2.2"
|
|
13 | 13 |
core = "7.x" |
14 | 14 |
project = "twitter_block" |
15 |
datestamp = "1373509571"
|
|
15 |
datestamp = "1404893628"
|
|
16 | 16 |
|
drupal7/sites/all/modules/twitter_block/twitter_block.install | ||
---|---|---|
32 | 32 |
'default' => '', |
33 | 33 |
'description' => 'Widget ID.', |
34 | 34 |
), |
35 |
'username' => array( |
|
36 |
'type' => 'varchar', |
|
37 |
'length' => 128, |
|
38 |
'not null' => TRUE, |
|
39 |
'default' => '', |
|
40 |
'description' => 'Account username.', |
|
41 |
), |
|
35 | 42 |
'data' => array( |
36 | 43 |
'type' => 'blob', |
37 | 44 |
'size' => 'big', |
... | ... | |
54 | 61 |
* Implements hook_uninstall(). |
55 | 62 |
*/ |
56 | 63 |
function twitter_block_uninstall() { |
57 |
// Remove blocks |
|
64 |
// Remove blocks.
|
|
58 | 65 |
db_delete('block') |
59 | 66 |
->condition('module', 'twitter_block') |
60 | 67 |
->execute(); |
... | ... | |
62 | 69 |
->condition('module', 'twitter_block') |
63 | 70 |
->execute(); |
64 | 71 |
|
65 |
// Clear the site cache |
|
72 |
// Remove variables. |
|
73 |
variable_del('twitter_block_cache'); |
|
74 |
variable_del('twitter_block_last_cache'); |
|
75 |
|
|
76 |
// Remove the cache directory. |
|
77 |
twitter_block_clear_js_cache(); |
|
78 |
|
|
79 |
// Clear the site cache. |
|
66 | 80 |
cache_clear_all(); |
67 | 81 |
} |
68 | 82 |
|
... | ... | |
70 | 84 |
* Remove any old Twitter Block blocks and install the new Twitter Block schema. |
71 | 85 |
*/ |
72 | 86 |
function twitter_block_update_7200() { |
73 |
// Remove old Twitter Block schema |
|
87 |
// Remove old Twitter Block schema.
|
|
74 | 88 |
drupal_uninstall_schema('twitter_block'); |
75 | 89 |
|
76 |
// Remove any old Twitter Block blocks |
|
90 |
// Remove any old Twitter Block blocks.
|
|
77 | 91 |
db_delete('block') |
78 | 92 |
->condition('module', 'twitter_block') |
79 | 93 |
->execute(); |
... | ... | |
81 | 95 |
->condition('module', 'twitter_block') |
82 | 96 |
->execute(); |
83 | 97 |
|
84 |
// Clear the site cache |
|
98 |
// Clear the site cache.
|
|
85 | 99 |
cache_clear_all(); |
86 | 100 |
|
87 |
// Install the new Twitter Block schema |
|
101 |
// Install the new Twitter Block schema.
|
|
88 | 102 |
drupal_install_schema('twitter_block'); |
89 | 103 |
|
90 | 104 |
return t('Removed any old Twitter Block blocks and installed the new Twitter Block schema.'); |
91 | 105 |
} |
106 |
|
|
107 |
/** |
|
108 |
* Add a column to the {twitter_block} table to store the Twitter account username. |
|
109 |
*/ |
|
110 |
function twitter_block_update_7201() { |
|
111 |
db_add_field('twitter_block', 'username', array( |
|
112 |
'type' => 'varchar', |
|
113 |
'length' => 128, |
|
114 |
'not null' => TRUE, |
|
115 |
'default' => '', |
|
116 |
'description' => 'Account username.', |
|
117 |
)); |
|
118 |
} |
drupal7/sites/all/modules/twitter_block/twitter_block.module | ||
---|---|---|
5 | 5 |
* A module to provide simple Twitter blocks using the Twitter Search API. |
6 | 6 |
*/ |
7 | 7 |
|
8 |
/** |
|
9 |
* Implements hook_cron(). |
|
10 |
*/ |
|
11 |
function twitter_block_cron() { |
|
12 |
// Regenerate the JavaScript file every day. |
|
13 |
if (REQUEST_TIME - variable_get('twitter_block_last_cache', 0) >= 86400 && variable_get('twitter_block_cache', TRUE)) { |
|
14 |
// Synchronize the widget code and update it if remote file have changed. |
|
15 |
twitter_block_cache(TRUE); |
|
16 |
|
|
17 |
// Record when the synchronization occurred. |
|
18 |
variable_set('twitter_block_last_cache', REQUEST_TIME); |
|
19 |
} |
|
20 |
} |
|
21 |
|
|
8 | 22 |
/** |
9 | 23 |
* Implements hook_help(). |
10 | 24 |
*/ |
... | ... | |
19 | 33 |
* Implements hook_menu(). |
20 | 34 |
*/ |
21 | 35 |
function twitter_block_menu() { |
22 |
// Create an array of block settings |
|
36 |
// Create an array of block settings.
|
|
23 | 37 |
$settings = array( |
24 | 38 |
'title' => 'Add Twitter block', |
25 | 39 |
'description' => 'Add a new Twitter block.', |
... | ... | |
29 | 43 |
'file' => 'twitter_block.admin.inc', |
30 | 44 |
); |
31 | 45 |
|
32 |
// Add a local action to the block configuration page |
|
46 |
// Add a local action to the block configuration page.
|
|
33 | 47 |
$items['admin/structure/block/add-twitter-block'] = array( |
34 | 48 |
'access arguments' => array('administer blocks'), |
35 | 49 |
) + $settings; |
36 | 50 |
|
37 |
// Get the default site theme |
|
51 |
// Get the default site theme.
|
|
38 | 52 |
$default_theme = variable_get('theme_default', 'bartik'); |
39 | 53 |
|
40 |
// Add a local action to the per-theme block configuration pages |
|
54 |
// Add a local action to the per-theme block configuration pages.
|
|
41 | 55 |
foreach (list_themes() as $key => $theme) { |
42 | 56 |
if ($key != $default_theme) { |
43 | 57 |
$items['admin/structure/block/list/' . $key . '/add-twitter-block'] = array( |
... | ... | |
71 | 85 |
function twitter_block_form_block_admin_display_form_alter(&$form, &$form_state, $form_id) { |
72 | 86 |
$result = db_query('SELECT bid FROM {twitter_block}'); |
73 | 87 |
|
74 |
// Add delete links to Twitter Block blocks |
|
88 |
// Add delete links to Twitter Block blocks.
|
|
75 | 89 |
foreach ($result as $block) { |
76 | 90 |
$form['blocks']['twitter_block_' . $block->bid]['delete'] = array( |
77 | 91 |
'#type' => 'link', |
... | ... | |
93 | 107 |
* - bid: Block ID. |
94 | 108 |
* - info: Block description. |
95 | 109 |
* - widget_id: Widget ID. |
110 |
* - username: Account username. |
|
96 | 111 |
* - theme: Theme. |
97 | 112 |
* - link_color: Link color. |
98 | 113 |
* - width: Width. |
... | ... | |
157 | 172 |
$edit += array( |
158 | 173 |
'info' => '', |
159 | 174 |
'widget_id' => '', |
175 |
'username' => '', |
|
160 | 176 |
'theme' => '', |
161 | 177 |
'link_color' => '', |
162 | 178 |
'width' => '', |
... | ... | |
184 | 200 |
'#required' => TRUE, |
185 | 201 |
'#description' => t('Each Twitter Block block requires a unique widget ID which determines, among other things, the source (user timeline, favourites, list or search) of the tweets to display. You can view a list of your existing embedded timeline widgets (and their widget IDs) or create new embedded timeline widgets by visiting the <a href="@widgets_section">widgets section of your settings page</a> (make sure that you\'re logged in). You can determine a widget\'s ID by editing it and inspecting the URL (which should be in the form of twitter.com/settings/widgets/WIDGET_ID/edit) or by looking at the widget\'s embed code (look for data-widget-id="WIDGET_ID").', array('@widgets_section' => 'https://twitter.com/settings/widgets')), |
186 | 202 |
); |
203 |
$form['username'] = array( |
|
204 |
'#type' => 'textfield', |
|
205 |
'#title' => t('Username'), |
|
206 |
'#default_value' => $edit['username'], |
|
207 |
'#required' => TRUE, |
|
208 |
'#description' => t('A Twitter account username. This is used to generate a fallback link to the Twitter account associated with the widget when JavaScript is not available. You can find your account username by visting the <a href="@account_section">account section of your settings page</a> or on your profile page in the URL or prefixed with @ under your display name.', array('@account_section' => 'https://twitter.com/settings/account')), |
|
209 |
); |
|
187 | 210 |
$form['appearance'] = array( |
188 | 211 |
'#type' => 'fieldset', |
189 | 212 |
'#title' => t('Appearance'), |
... | ... | |
311 | 334 |
* Associative array of fields to save. Array keys: |
312 | 335 |
* - info: Block description. |
313 | 336 |
* - widget_id: Widget ID. |
337 |
* - username: Account username. |
|
314 | 338 |
* - theme: Theme. |
315 | 339 |
* - link_color: Link color. |
316 | 340 |
* - width: Width. |
... | ... | |
342 | 366 |
'polite' => $edit['polite'], |
343 | 367 |
); |
344 | 368 |
|
345 |
// Save the block configuration |
|
369 |
// Save the block configuration.
|
|
346 | 370 |
$delta = db_update('twitter_block') |
347 | 371 |
->fields(array( |
348 | 372 |
'info' => $edit['info'], |
349 | 373 |
'widget_id' => $edit['widget_id'], |
374 |
'username' => $edit['username'], |
|
350 | 375 |
'data' => serialize($data), |
351 | 376 |
)) |
352 | 377 |
->condition('bid', $delta) |
... | ... | |
362 | 387 |
// Load the configuration. |
363 | 388 |
$config = twitter_block_block_get($delta); |
364 | 389 |
|
365 |
// Unserialize the timeline
|
|
390 |
// Unserialize the timeline.
|
|
366 | 391 |
$data = unserialize($config['data']); |
367 | 392 |
|
368 | 393 |
$block = array(); |
369 | 394 |
$block['subject'] = check_plain($config['info']); |
370 | 395 |
$block['content'] = array( |
371 |
'#theme' => 'link',
|
|
372 |
'#text' => 'Tweets by @twitterapi',
|
|
373 |
'#path' => 'https://twitter.com/twitterapi',
|
|
396 |
'#type' => 'link',
|
|
397 |
'#title' => t('Tweets by @username', array('@username' => $config['username'])),
|
|
398 |
'#href' => 'https://twitter.com/' . $config['username'],
|
|
374 | 399 |
'#options' => array( |
375 | 400 |
'attributes' => array( |
376 | 401 |
'class' => array('twitter-timeline'), |
... | ... | |
378 | 403 |
), |
379 | 404 |
'html' => FALSE, |
380 | 405 |
), |
381 |
'#attached' => array( |
|
382 |
'js' => array( |
|
383 |
'https://platform.twitter.com/widgets.js' => array( |
|
384 |
'type' => 'external', |
|
385 |
), |
|
386 |
), |
|
387 |
), |
|
388 | 406 |
); |
389 | 407 |
|
408 |
// Use a locally cached copy of widgets.js by default. |
|
409 |
if (variable_get('twitter_block_cache', TRUE) && $url = twitter_block_cache()) { |
|
410 |
$block['content']['#attached']['js'] = array( |
|
411 |
array( |
|
412 |
'data' => $url, |
|
413 |
'type' => 'file', |
|
414 |
), |
|
415 |
); |
|
416 |
} |
|
417 |
else { |
|
418 |
$block['content']['#attached']['js'] = array( |
|
419 |
'//platform.twitter.com/widgets.js' => array( |
|
420 |
'type' => 'external', |
|
421 |
'scope' => 'footer', |
|
422 |
), |
|
423 |
); |
|
424 |
} |
|
425 |
|
|
390 | 426 |
if (!empty($data['theme'])) { |
391 | 427 |
$block['content']['#options']['attributes']['data-theme'] = $data['theme']; |
392 | 428 |
} |
... | ... | |
434 | 470 |
} |
435 | 471 |
|
436 | 472 |
if (!empty($data['polite'])) { |
437 |
$block['content']['#options']['attributes']['aria-polite'] = $data['polite']; |
|
473 |
$block['content']['#options']['attributes']['data-aria-polite'] = $data['polite'];
|
|
438 | 474 |
} |
439 | 475 |
|
440 | 476 |
return $block; |
441 | 477 |
} |
478 |
|
|
479 |
/** |
|
480 |
* Download/Synchronize/Cache widget code file locally. |
|
481 |
* |
|
482 |
* @param $sync_cached_file |
|
483 |
* Synchronize widget code and update if remote file have changed. |
|
484 |
* @return mixed |
|
485 |
* The path to the local javascript file on success, boolean FALSE on failure. |
|
486 |
*/ |
|
487 |
function twitter_block_cache($sync_cached_file = FALSE) { |
|
488 |
$location = 'http://platform.twitter.com/widgets.js'; |
|
489 |
$path = 'public://twitter_block'; |
|
490 |
$file_destination = $path . '/' . basename($location); |
|
491 |
|
|
492 |
if (!file_exists($file_destination) || $sync_cached_file) { |
|
493 |
// Download the latest widget code. |
|
494 |
$result = drupal_http_request($location); |
|
495 |
|
|
496 |
if ($result->code == 200) { |
|
497 |
if (file_exists($file_destination)) { |
|
498 |
// Synchronize widget code and and replace local file if outdated. |
|
499 |
$data_hash_local = drupal_hash_base64(file_get_contents($file_destination)); |
|
500 |
$data_hash_remote = drupal_hash_base64($result->data); |
|
501 |
// Check that the files directory is writable. |
|
502 |
if ($data_hash_local != $data_hash_remote && file_prepare_directory($path)) { |
|
503 |
// Save updated widget code file to disk. |
|
504 |
file_unmanaged_save_data($result->data, $file_destination, FILE_EXISTS_REPLACE); |
|
505 |
watchdog('twitter_block', 'Locally cached widget code file has been updated.', array(), WATCHDOG_INFO); |
|
506 |
|
|
507 |
// Change query-strings on css/js files to enforce reload for all users. |
|
508 |
_drupal_flush_css_js(); |
|
509 |
} |
|
510 |
} |
|
511 |
else { |
|
512 |
// Check that the files directory is writable. |
|
513 |
if (file_prepare_directory($path, FILE_CREATE_DIRECTORY)) { |
|
514 |
// There is no need to flush JS here as core refreshes JS caches |
|
515 |
// automatically, if new files are added. |
|
516 |
file_unmanaged_save_data($result->data, $file_destination, FILE_EXISTS_REPLACE); |
|
517 |
watchdog('twitter_block', 'Locally cached widget code file has been saved.', array(), WATCHDOG_INFO); |
|
518 |
|
|
519 |
// Return the local JS file path. |
|
520 |
return file_create_url($file_destination); |
|
521 |
} |
|
522 |
} |
|
523 |
} |
|
524 |
} |
|
525 |
else { |
|
526 |
// Return the local JS file path. |
|
527 |
return file_create_url($file_destination); |
|
528 |
} |
|
529 |
} |
|
530 |
|
|
531 |
/** |
|
532 |
* Delete cached files and directory. |
|
533 |
*/ |
|
534 |
function twitter_block_clear_js_cache() { |
|
535 |
$path = 'public://twitter_block'; |
|
536 |
if (file_prepare_directory($path)) { |
|
537 |
file_scan_directory($path, '/.*/', array('callback' => 'file_unmanaged_delete')); |
|
538 |
drupal_rmdir($path); |
|
539 |
|
|
540 |
// Change query-strings on css/js files to enforce reload for all users. |
|
541 |
_drupal_flush_css_js(); |
|
542 |
|
|
543 |
watchdog('twitter_block', 'Local cache has been purged.', array(), WATCHDOG_INFO); |
|
544 |
} |
|
545 |
} |
Formats disponibles : Unified diff
Weekly update of contrib modules