| 1 |
<?php |
<?php |
| 2 |
// $Id: comment_info.module,v 1.1.2.1.2.5 2007/03/20 23:33:38 mfer Exp $ |
// $Id: comment_info.module,v 1.1.2.1.2.6 2007/04/01 21:43:16 mfer Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 18 |
} |
} |
| 19 |
} |
} |
| 20 |
|
|
|
/** |
|
|
* Implementation of hook_menu(). |
|
|
*/ |
|
|
function comment_info_menu($may_cache) { |
|
|
$items = array(); |
|
|
if ($may_cache) { |
|
|
$items[] = array( |
|
|
'path' => 'admin/settings/comment_info', |
|
|
'title' => t('Comment Info'), |
|
|
'description' => t('Administer Comment Info Configuration.'), |
|
|
'callback' => 'drupal_get_form', |
|
|
'callback arguments' => array('comment_info_admin_settings'), |
|
|
'access' => user_access('administer site configuration'), |
|
|
'type' => MENU_NORMAL_ITEM, |
|
|
); |
|
|
} |
|
|
return $items; |
|
|
} |
|
|
|
|
|
/** |
|
|
* Helper function generates admin settings page. |
|
|
*/ |
|
|
function comment_info_admin_settings() { |
|
|
$form['comment_info_description'] = array( |
|
|
'#value' => t('The Comment Info module allows anonymous users to save their comment information. There are two methods for storing the anonymous users information. The classic way via the users session and using jQuery with cookies. Using the jQuery method will only work in javascript enabled browsers. The jQuery method is the only method that works with caching and is therefore the default/only option when caching is enabled.') |
|
|
); |
|
|
|
|
|
$form['comment_info_setting'] = array( |
|
|
'#type' => 'checkbox', |
|
|
'#title' => t('Enable jQuery Comment Info.'), |
|
|
'#default_value' => variable_get('comment_info_setting', 0), |
|
|
); |
|
|
|
|
|
if (variable_get('cache', CACHE_DISABLED) != CACHE_DISABLED) { |
|
|
$form['comment_info_setting']['#default_value'] = 1; |
|
|
$form['comment_info_setting']['#disabled'] = true; |
|
|
} |
|
|
|
|
|
return system_settings_form($form); |
|
|
} |
|
|
|
|
| 21 |
/** |
/** |
| 22 |
* Insert our checkbox, and populate fields. |
* Insert our checkbox, and populate fields. |
| 23 |
* set validation hook. |
* set validation hook. |
| 28 |
if ($user->uid || ($form_id != 'comment_form')) { |
if ($user->uid || ($form_id != 'comment_form')) { |
| 29 |
return; |
return; |
| 30 |
} |
} |
| 31 |
$form['comment_info']['optin'] = array( |
drupal_add_js(drupal_get_path('module', 'comment_info').'/comment_info.js'); |
| 32 |
'#type' => 'checkbox', |
$form['#validate']['comment_info_validate'] = array(); |
|
'#title' => t('Save my Comment Information for next time.'), |
|
|
); |
|
|
if (variable_get('comment_info_setting', 0) == 1 || variable_get('cache', CACHE_DISABLED) != CACHE_DISABLED) { |
|
|
drupal_add_js(drupal_get_path('module', 'comment_info').'/comment_info.js'); |
|
|
$form['comment_info']['optin']['#attributes'] = array('style' => 'display:none;'); |
|
|
} |
|
|
|
|
|
else { |
|
|
foreach (array('name','homepage','mail') as $field) { |
|
|
if (is_array($form[$field]) && $_SESSION['comment_info']['optin']) { |
|
|
$form[$field]['#value'] = $_SESSION['comment_info'][$field]; |
|
|
} |
|
|
} |
|
|
|
|
|
$form['#validate']['comment_info_validate'] = array(); |
|
|
|
|
|
$form['comment_info']['optin']['#default_value'] = $_SESSION['comment_info']['optin']; |
|
|
} |
|
| 33 |
} |
} |
| 34 |
|
|
| 35 |
/** |
/** |
| 36 |
* save our data. |
* save our data. |
| 37 |
*/ |
*/ |
| 38 |
function comment_info_validate($form_id, $form_values) { |
function comment_info_validate($form_id, $form_values) { |
| 39 |
|
global $user; |
| 40 |
if ($form_values['optin']) { |
if (!$user->uid) { |
| 41 |
foreach (array('name','homepage','mail','optin') as $field) { |
foreach (array('name', 'homepage', 'mail') as $field) { |
| 42 |
$_SESSION['comment_info'][$field] = $form_values[$field]; |
// Set cookie for 365 days. |
| 43 |
} |
if (isset($form_values[$field])) { |
| 44 |
} else { |
setcookie('comment_info_'. $field, $form_values[$field], time() + 31536000, '/'); |
| 45 |
foreach (array('name','homepage','mail','optin') as $field) { |
} |
|
unset($_SESSION['comment_info'][$field]); |
|
| 46 |
} |
} |
| 47 |
} |
} |
| 48 |
} |
} |