[phpmix-cvs] drupal/modules/akismet akismet.module,1.10,1.11
Status: Pre-Alpha
Brought to you by:
markus_petrux
From: <php...@li...> - 2006-06-09 09:02:22
|
Update of /cvsroot/phpmix/drupal/modules/akismet In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9446 Modified Files: akismet.module Log Message: Implemented customizable (and themable) block to display the akismet spam counter. There is also a new option in the settings panel that allows administrators set how many blocks they wish to use (or none at all). This is aimed to keep the block administration panel as clean as possible. Index: akismet.module =================================================================== RCS file: /cvsroot/phpmix/drupal/modules/akismet/akismet.module,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** akismet.module 8 Jun 2006 01:38:31 -0000 1.10 --- akismet.module 9 Jun 2006 09:02:12 -0000 1.11 *************** *** 4,8 **** /********************************************************************************\ - @TODO: Implement a themable block (or something for spam counter). @TODO: Implement an opt-in option for administrators to e-mail them when content is posted (maybe for all posts, or for detected spam or nothing). --- 4,7 ---- *************** *** 284,287 **** --- 283,295 ---- '#description' => t('The maximum number of records per page on moderation queue.') ); + $form['general']['akismet_blocks_counter'] = array( + '#type' => 'select', '#title' => t('Number of blocks'), + '#default_value' => variable_get('akismet_blocks_counter', 1), + '#options' => array(0=>t('none'), 1=>1, 2=>2, 3=>3, 4=>4, 5=>5), + '#description' => t('The akismet module may generate a number of blocks for you to display the current spam counter anywhere on your site. The number of blocks is variable to help you keep your <a href="%admin-block">blocks administration panel</a> as clean as possible. This option allows you to specify how many blocks you wish to use. If you do not plan to show the spam counter to your visitors, set this option to <em>none</em>.', + array( + '%admin-block' => url('admin/block') + )) + ); $form['node_options'] = array( *************** *** 430,433 **** --- 438,586 ---- /** + * Implementation of hook_block(). + */ + function akismet_block($op = 'list', $delta = 0, $edit = array()) { + static $block_fields = FALSE; + if (!$block_fields) { + $block_fields = array( + 'type' => array( + '#type' => 'radios', + '#title' => t('Display counter as'), + '#options' => array('image' => t('Image'), 'text' => t('Text')), + '#default_value' => 'image' + ), + 'sitename' => array( + '#type' => 'radios', + '#title' => t('Show site name'), + '#options' => array('1' => t('Enabled'), '0' => t('Disabled')), + '#default_value' => '1' + ), + 'newwin' => array( + '#type' => 'radios', + '#title' => t('Open Akismet link in new window'), + '#options' => array('1' => t('Enabled'), '0' => t('Disabled')), + '#default_value' => '1' + ) + ); + } + switch ($op) { + case 'list': + $blocks_counter = variable_get('akismet_blocks_counter', 1); + $blocks = array(); + for ($i = 0; $i < $blocks_counter; $i++) { + $blocks[] = array('info' => t('Akismet spam counter (block:%count)', array('%count' => ($i+1)))); + } + return $blocks; + + case 'configure': + if ($delta < 0 || $delta >= variable_get('akismet_blocks_counter', 1)) { + drupal_set_message(t('Oops! You are requesting a non-existing block, changes will not be saved.'), 'error'); + break; + } + $form = array(); + $form['description'] = array( + '#type' => 'markup', + '#value' => '<div class="description"><p>'. t('These options allow to customize the look of this <em>akismet spam counter</em> block.') .'</p></div>' + ); + $block_settings = variable_get('akismet_blocks_'. $delta, FALSE); + foreach ($block_fields as $field_key => $field_info) { + $field_name = 'akismet_blocks_'. $delta .'_'. $field_key; + $form[$field_name] = array(); + foreach ($field_info as $key => $value) { + $form[$field_name][$key] = $value; + } + if ($block_settings && isset($block_settings[$field_key])) { + $form[$field_name]['#default_value'] = $block_settings[$field_key]; + } + } + return $form; + + case 'save': + if ($delta < 0 || $delta >= variable_get('akismet_blocks_counter', 1)) { + drupal_set_message(t('Oops! You have requested a non-existing block, changes were not saved.'), 'error'); + break; + } + $block_settings = array(); + foreach ($block_fields as $field_key => $field_info) { + $field_name = 'akismet_blocks_'. $delta .'_'. $field_key; + $block_settings[$field_key] = $edit[$field_name]; + } + variable_set('akismet_blocks_'. $delta, $block_settings); + break; + + case 'view': + if ($delta >= 0 && $delta < variable_get('akismet_blocks_counter', 1)) { + $block_settings = variable_get('akismet_blocks_'. $delta, FALSE); + if (!$block_settings) { + $block_settings = array(); + } + + $block_args = array( + 'content' => '', // Built below. + 'counter' => variable_get('akismet_counter_spam', 0), + 'since' => akismet_get_counting_since(), + 'text' => '', // Built below. + 'image' => '', // Built below. + 'block' => array('delta' => $delta) // completed below with current block settings. + ); + + foreach ($block_fields as $field_key => $field_info) { + if (!isset($block_settings[$field_key])) { + $block_settings[$field_key] = $field_info['#default_value']; + } + $block_args['block'][$field_key] = $block_settings[$field_key]; + } + + $target = ($block_settings['newwin'] ? ' target="_blank"' : ''); + $block_args['text'] = array( + 'plain' => array( + 'short' => check_plain(t('Proudly protected by Akismet, %count spam caught since %since.', array('%site_name' => variable_get('site_name', 'drupal'), '%count' => $block_args['counter'], '%since' => $block_args['since']))), + 'long' => check_plain(t('%site_name is proudly protected by Akismet, %count spam caught since %since.', array('%site_name' => variable_get('site_name', 'drupal'), '%count' => $block_args['counter'], '%since' => $block_args['since']))) + ), + 'html' => array( + 'short' => t('Proudly protected by <a href="%akismet"%target>Akismet</a>, %count spam caught since %since', array('%site_name' => variable_get('site_name', 'drupal'), '%akismet' => 'http://akismet.com', '%target' => $target, '%count' => $block_args['counter'], '%since' => $block_args['since'])), + 'long' => t('%site_name is proudly protected by <a href="%akismet"%target>Akismet</a>, %count spam caught since %since', array('%site_name' => variable_get('site_name', 'drupal'), '%akismet' => 'http://akismet.com', '%target' => $target, '%count' => $block_args['counter'], '%since' => $block_args['since'])) + ) + ); + $text_version = ($block_settings['sitename'] ? 'long' : 'short'); + $title_text = $block_args['text']['plain'][$text_version]; + $image_url = base_path() . drupal_get_path('module', 'akismet') .'/akismet.gif'; + $block_args['image'] = '<img src="'. $image_url .'" title="'. $title_text .'" alt="'. $title_text .'" />'; + + if ($block_settings['type'] == 'image') { + $block_args['content'] = '<a href="http://akismet.com" title="'. $title_text .'"'. $target .'>'. $block_args['image'] .'</a>'; + } + else { + $block_args['content'] = $block_args['text']['html'][$text_version]; + } + + $block = array(); + $block['subject'] = t('Akismet spam counter'); + $block['content'] = theme('akismet_counter_block', $block_args); + return $block; + } + break; + } + } + + /** + * Allow themes customize the content of the akismet spam counter block. + * + * @param array arguments where each element is: + * content: String; the completely built block content. + * counter: Integer; the current spam counter. + * since : String; the formatted 'counting since' date. + * text : Array; with 2 subarrays defined as follows: + * plain: Array with 2 elements ('short' and 'long'). + * html : Array with 2 elements ('short' and 'long'). + * image : String; the completely built IMG tag. + * block : Array; Block settings. + * @return string The content of the block. + */ + function theme_akismet_counter_block($args) { + return $args['content']; + } + + /** * Implementation of hook_menu(). */ *************** *** 775,778 **** --- 928,933 ---- /** * Menu callback; Moderation queue. + * + * @param string Operation code: overview (default), nodes, comments. */ function akismet_callback_queue($op = '') { |