[phpmix-cvs] drupal/modules/akismet akismet.module,1.11,1.12
Status: Pre-Alpha
Brought to you by:
markus_petrux
From: <php...@li...> - 2006-06-10 00:58:01
|
Update of /cvsroot/phpmix/drupal/modules/akismet In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24482 Modified Files: akismet.module Log Message: Implemented automatic version checker. Index: akismet.module =================================================================== RCS file: /cvsroot/phpmix/drupal/modules/akismet/akismet.module,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** akismet.module 9 Jun 2006 09:02:12 -0000 1.11 --- akismet.module 10 Jun 2006 00:57:54 -0000 1.12 *************** *** 12,15 **** --- 12,23 ---- /** + * Akismet Drupal and Module versions. + */ + define('AKISMET_DRUPAL_VERSION', '4.7'); + define('AKISMET_MODULE_VERSION', '1.0.0 beta'); + define('AKISMET_MODULE_HOMEURL', 'http://www.phpmix.org/projects/drupal/4_7/akismet'); + + + /** * Akismet API constants. */ *************** *** 17,21 **** define('AKISMET_API_PORT', 80); define('AKISMET_API_VERSION', '1.1'); ! define('AKISMET_USERAGENT', 'Drupal/4.7 | akismet.module/1.0'); define('AKISMET_API_RESULT_ERROR', -1); define('AKISMET_API_RESULT_SUCCESS', 0); --- 25,29 ---- define('AKISMET_API_PORT', 80); define('AKISMET_API_VERSION', '1.1'); ! define('AKISMET_USERAGENT', 'Drupal/'. AKISMET_DRUPAL_VERSION .' | akismet.module/'. AKISMET_MODULE_VERSION); define('AKISMET_API_RESULT_ERROR', -1); define('AKISMET_API_RESULT_SUCCESS', 0); *************** *** 25,28 **** --- 33,114 ---- /** + * Check module version. + * + * @param boolean FALSE will return a cached value (if exists); otherwise it will perform a real time connection. + * @return string The latest released module version, + * NFND if the server reports "Module Not Found" (something that shouldn't happen) or + * an empty string if connection fails (reason logged to watchdog). + */ + function _akismet_check_version($refresh = FALSE) { + $version_string = variable_get('akismet_version_string', FALSE); + $timestamp_now = time(); + if (!$version_string) { + $refresh = TRUE; + } + else { + $timestamp_age = variable_get('akismet_version_check_age', 604800); + if ($timestamp_age > 0) { + $timestamp_last = variable_get('akismet_version_check_timestamp', 0); + if (($timestamp_last + $timestamp_age) < $timestamp_now) { + $refresh = TRUE; + } + } + } + if ($refresh) { + $version_url = AKISMET_MODULE_HOMEURL .'/version'; + $result = drupal_http_request($version_url); + if (!isset($result->code) || !in_array($result->code, array(200,302,307)) || empty($result->data)) { + watchdog('version check', t('Could not check version of akismet module, due to "%error".', array('%error' => theme('placeholder', $result->code .' '. $result->error))), WATCHDOG_ERROR, l(t('check'), $version_url, array('target'=>'_blank'), NULL, NULL, TRUE)); + return ''; + } + $new_version = trim($result->data); + if (AKISMET_MODULE_VERSION != $new_version) { + watchdog('version check', t('New version of akismet module seems to be available. Your currently installed version is <strong>%your-version</strong>. The latest available version is <strong>%new-version</strong>.', array('%your-version' => AKISMET_MODULE_VERSION, '%new-version' => $new_version)), WATCHDOG_WARNING, l(t('module home'), AKISMET_MODULE_HOMEURL, array('target'=>'_blank'), NULL, NULL, TRUE)); + } + else { + watchdog('version check', t('Your version of akismet module is up to date.'), WATCHDOG_WARNING, l(t('module home'), AKISMET_MODULE_HOMEURL, array('target'=>'_blank'), NULL, NULL, TRUE)); + } + $version_string = $new_version; + variable_set('akismet_version_string', $version_string); + variable_set('akismet_version_check_timestamp', $timestamp_now); + } + return $version_string; + } + + /** + * Get version information message. + * + * @param string URL of the current page. + * @return string + */ + function _akismet_get_version_message($url) { + global $user; + if ($user->uid != 1) { + return ''; + } + $new_version = _akismet_check_version(isset($_GET['vchk']) ? TRUE : FALSE); + $output = '<p>'; + if (empty($new_version)) { + $output .= t('Sorry, could not connect to remote server to check for version information. Please, consult the <a href="%admin-logs">log</a> for details.', array('%admin-logs' => url('admin/logs'))); + } + else { + if (isset($_GET['vchk'])) { + drupal_goto($url); + } + if ($new_version != AKISMET_MODULE_VERSION) { + $output .= t('Your installation does <strong>not</strong> seem to be up to date. Updates are available, please visit the <a href="%module-url" target="_blank">Akismet module home</a> to obtain the latest version. The latest available version is <strong>%new-version</strong>. ', array('%module-url' => AKISMET_MODULE_HOMEURL, '%new-version' => $new_version)); + } + } + $output .= t('You are running version <strong>%your-version</strong>.', array('%your-version' => AKISMET_MODULE_VERSION)); + $timestamp_last = variable_get('akismet_version_check_timestamp', 0); + if ($timestamp_last) { + $output .= ' '. t('Last time checked: <strong>%last</strong>. The time is now %time.', array('%last' => format_date($timestamp_last), '%time' => format_date(time()))); + } + $output .= ' '. t('<a href="%check">Check for newest version</a>.', array('%check' => url($url, 'vchk=1'))); + $output .= '</p>'; + return $output; + } + + /** * Implementation of hook_help(). */ *************** *** 37,46 **** $output = t('<p>The <a href="%akismet-module-home">akismet module</a> for <a href="%drupal">Drupal</a> allows you to use the <a href="%akismet">Akismet Service</a> to protect your site from being spammed.</p>', array( ! '%akismet-module-home' => 'http://www.phpmix.org/projects/drupal', '%drupal' => 'http://drupal.org', '%akismet' => 'http://akismet.com' )); case 'admin/akismet': ! $output .= t('<p>Akismet has caught <strong>%count spam</strong> for you since <strong>%since</strong>.</p>', array('%count' => variable_get('akismet_counter_spam', 0), '%since' => akismet_get_counting_since())); if ($section == 'admin/settings/akismet') { $output .= theme('more_help_link', url('admin/help/akismet')); --- 123,135 ---- $output = t('<p>The <a href="%akismet-module-home">akismet module</a> for <a href="%drupal">Drupal</a> allows you to use the <a href="%akismet">Akismet Service</a> to protect your site from being spammed.</p>', array( ! '%akismet-module-home' => AKISMET_MODULE_HOMEURL, '%drupal' => 'http://drupal.org', '%akismet' => 'http://akismet.com' )); + if ($section == 'admin/settings/akismet') { + $output .= _akismet_get_version_message($section); + } case 'admin/akismet': ! $output .= t('<p>Akismet has caught <strong>%count spam</strong> for you since <strong>%since</strong>.</p>', array('%count' => akismet_get_spam_counter(), '%since' => akismet_get_counting_since())); if ($section == 'admin/settings/akismet') { $output .= theme('more_help_link', url('admin/help/akismet')); *************** *** 223,231 **** } ! $form['general'] = array( ! '#type' => 'fieldset', '#title' => t('General settings'), '#collapsible' => TRUE, '#collapsed' => $akismet_collapsed ); ! $form['general']['akismet_wpapikey'] = array( '#type' => 'textfield', '#title' => t('WordPress.com API key'), '#size' => 30, '#maxlength' => 60, --- 312,320 ---- } ! $form['service'] = array( ! '#type' => 'fieldset', '#title' => t('Akismet Service Options'), '#collapsible' => TRUE, '#collapsed' => $akismet_collapsed ); ! $form['service']['akismet_wpapikey'] = array( '#type' => 'textfield', '#title' => t('WordPress.com API key'), '#size' => 30, '#maxlength' => 60, *************** *** 240,246 **** ); if (!empty($akismet_wpapikey) && !$is_valid) { ! $form['general']['akismet_wpapikey']['#description'] .= '<div class="marker">'. t("<strong>WARNING: Your API Key doesn't seem to be valid!</strong>") .'</div>'; } ! $form['general']['akismet_connection_enabled'] = array( '#type' => 'radios', '#title' => t('Akismet connections'), --- 329,335 ---- ); if (!empty($akismet_wpapikey) && !$is_valid) { ! $form['service']['akismet_wpapikey']['#description'] .= '<div class="marker">'. t("<strong>WARNING: Your API Key doesn't seem to be valid!</strong>") .'</div>'; } ! $form['service']['akismet_connection_enabled'] = array( '#type' => 'radios', '#title' => t('Akismet connections'), *************** *** 257,261 **** $timeout_options[$n] = $n; } ! $form['general']['akismet_connection_timeout'] = array( '#type' => 'select', '#title' => t('Connection timeout'), '#default_value' => variable_get('akismet_connection_timeout', 10), --- 346,350 ---- $timeout_options[$n] = $n; } ! $form['service']['akismet_connection_timeout'] = array( '#type' => 'select', '#title' => t('Connection timeout'), '#default_value' => variable_get('akismet_connection_timeout', 10), *************** *** 263,266 **** --- 352,369 ---- '#description' => t('This option allows you to specify the connection timeout in seconds that is used for real time Akismet connections.') ); + + $form['general'] = array( + '#type' => 'fieldset', '#title' => t('General Options'), + '#collapsible' => TRUE, '#collapsed' => $akismet_collapsed + ); + $age_options = drupal_map_assoc(array(0, 86400, 259200, 604800, 1209600), 'format_interval'); + $age_options[0] = t('never'); + $age_options[2592000] = t('1 month'); + $form['general']['akismet_version_check_age'] = array( + '#type' => 'select', '#title' => t('Check for updates every'), + '#default_value' => variable_get('akismet_version_check_age', 604800), + '#options' => $age_options, + '#description' => t('This option allows you to customize how often the akismet module will check for updates. To disable automatic version checks you can set this option to <em>none</em>. This process is automated through cron task, but it may also be triggered when module version is displayed on top of this panel.') + ); $age_options = drupal_map_assoc(array(0, 3600, 10800, 21600, 32400, 43200, 86400, 172800, 259200, 604800, 1209600, 1814400), 'format_interval'); $age_options[0] = t('never'); *************** *** 294,298 **** $form['node_options'] = array( ! '#type' => 'fieldset', '#title' => t('Node options'), '#collapsible' => TRUE, '#collapsed' => TRUE ); --- 397,401 ---- $form['node_options'] = array( ! '#type' => 'fieldset', '#title' => t('Node Options'), '#collapsible' => TRUE, '#collapsed' => TRUE ); *************** *** 338,342 **** if (module_exist('comment')) { $form['comment_options'] = array( ! '#type' => 'fieldset', '#title' => t('Comment options'), '#collapsible' => TRUE, '#collapsed' => TRUE ); --- 441,445 ---- if (module_exist('comment')) { $form['comment_options'] = array( ! '#type' => 'fieldset', '#title' => t('Comment Options'), '#collapsible' => TRUE, '#collapsed' => TRUE ); *************** *** 394,403 **** $form['counter_options'] = array( ! '#type' => 'fieldset', '#title' => t('Counter options'), '#collapsible' => TRUE, '#collapsed' => TRUE ); $form['counter_options']['akismet_counter_spam'] = array( '#type' => 'textfield', '#title' => t('Spam counter'), ! '#default_value' => variable_get('akismet_counter_spam', 0), '#size' => 10, '#maxlength' => 10, '#description' => t('This counter is incremented for every spam caught by Akismet.') --- 497,506 ---- $form['counter_options'] = array( ! '#type' => 'fieldset', '#title' => t('Spam Counter Options'), '#collapsible' => TRUE, '#collapsed' => TRUE ); $form['counter_options']['akismet_counter_spam'] = array( '#type' => 'textfield', '#title' => t('Spam counter'), ! '#default_value' => akismet_get_spam_counter(), '#size' => 10, '#maxlength' => 10, '#description' => t('This counter is incremented for every spam caught by Akismet.') *************** *** 419,422 **** --- 522,534 ---- /** + * Get the current akismet spam counter. + * + * @return integer + */ + function akismet_get_spam_counter() { + return (int)variable_get('akismet_counter_spam', 0); + } + + /** * Format the 'Counting since' date. * *************** *** 518,522 **** $block_args = array( 'content' => '', // Built below. ! 'counter' => variable_get('akismet_counter_spam', 0), 'since' => akismet_get_counting_since(), 'text' => '', // Built below. --- 630,634 ---- $block_args = array( 'content' => '', // Built below. ! 'counter' => akismet_get_spam_counter(), 'since' => akismet_get_counting_since(), 'text' => '', // Built below. *************** *** 792,796 **** akismet_content_spam_operation('node', $node, 'submit-spam', FALSE); // Increment Akismet spam counter ! variable_set('akismet_counter_spam', intval(variable_get('akismet_counter_spam', 0)) + 1); } --- 904,908 ---- akismet_content_spam_operation('node', $node, 'submit-spam', FALSE); // Increment Akismet spam counter ! variable_set('akismet_counter_spam', akismet_get_spam_counter() + 1); } *************** *** 900,904 **** akismet_content_spam_operation('comment', $comment, 'submit-spam', FALSE); // Increment Akismet spam counter ! variable_set('akismet_counter_spam', intval(variable_get('akismet_counter_spam', 0)) + 1); } --- 1012,1016 ---- akismet_content_spam_operation('comment', $comment, 'submit-spam', FALSE); // Increment Akismet spam counter ! variable_set('akismet_counter_spam', akismet_get_spam_counter() + 1); } |