--- flattr.module +++ (clipboard) @@ -9,6 +9,86 @@ * Stefan Auditor * Daniel Wehner */ + +/** +* Implementation of hook_menu +*/ +function flattr_menu() { + $items = array(); + + $items['admin/settings/flattr'] = array( + 'title' => 'Flattr', + 'description' => 'Flattr social micropayment', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('flattr_admin_settings'), + 'access arguments' => array('administer flattr'), + ); + + return $items; +} + +/** + * Implementation of admin_settings callback +*/ +function flattr_admin_settings(&$form_state) { + $form = array(); + + $form['fieldset_accounts'] = array( + '#type' => 'fieldset', + '#title' => t('Site wide account settings'), + '#collapsible' => FALSE, + '#description' => t("Configure what accounts are used for Flattr site wide"), + ); + + $form['fieldset_accounts']['flattr_sitewide_useage'] = array( + '#type' => 'radios', + '#title' => t('Site wide useage'), + '#default_value' => variable_get('flattr_sitewide_useage', 2), + '#options' => array( + t('Site wide account only, no per user accounts'), + t('Site wide account, with users own accounts overriding'), + t('Users have own code (no site wide account)') + ), + ); + + $form['fieldset_accounts']['flattr_sitewide_account'] = array( + '#type' => 'textfield', + '#title' => t('Site wide Flattr account username'), + '#default_value' => variable_get('flattr_sitewide_account', 'drupal'), + '#size' => 60, + '#maxlength' => 128, + '#required' => TRUE, + ); + + $form['fieldset_mapping'] = array( + '#type' => 'fieldset', + '#title' => t('Content mapping'), + '#collapsible' => FALSE, + '#description' => t("Configure what Flattr categories your content will appear in"), + ); + + $node_types = node_get_types('types'); + foreach ($node_types as $node_type => $node_type_more) { + $form['fieldset_mapping']['flattr_cat_'. $node_type] = array( + '#type' => 'select', + '#title' => t('%contenttype content type', array('%contenttype' => $node_type_more->name)) .' - ' . $node_type, + '#default_value' => variable_get('flattr_cat_'. $node_type, 'text'), + '#options' => array( + '' => t("Don't use flattr"), + 'text' => t('Written text'), + 'images' => t('Images'), + 'video' => t('Video'), + 'audio' => t('Audio'), + 'software' => t('Software'), + 'rest' => t('The rest'), + ), + ); + } + + $form = system_settings_form($form); + + return $form; +} /** * Impement HOOK_form_alter(). @@ -63,7 +143,7 @@ */ function flattr_user($op, &$edit, &$account, $category = NULL) { if ($op == 'form' && $category == 'account') { - if (user_access('use flattr', $account)) { + if (user_access('use flattr', $account) && variable_get('flattr_sitewide_useage', 2)) { $form['flattr'] = array( '#type' => 'fieldset', '#title' => t('Flattr social micropayment'), @@ -73,9 +153,9 @@ ); $form['flattr']['uid'] = array( '#type' => 'textfield', - '#title' => t('User ID'), + '#title' => t('Your Flattr user name'), '#default_value' => $edit['flattr']['uid'], - '#description' => t('Your signature will be publicly displayed at the end of your comments.'), + '#description' => t('Put your Flattr username here to make your content Flattr\'able.'), ); return $form; } @@ -94,12 +174,13 @@ ); return $blocks; case 'view': + $block['subject'] = t('Flattr'); + $account = NULL; if ($node = menu_get_object()) { $account = user_load($node->uid); - $block['subject'] = t('Flattr'); - $block['content'] = theme('flattr_button', $node, $account); - return $block; } + $block['content'] = theme('flattr_button', $node, $account); + return $block; } } @@ -111,7 +192,7 @@ case 'view': if (variable_get('flattr_cat_' . $node->type, NULL)) { $account = user_load($node->uid); - if (user_access('use flattr', $account) && $account->flattr['uid'] && !$a3) { + if (user_access('use flattr', $account) && ($account->flattr['uid'] || variable_get('flattr_sitewide_useage', 2) == 0)&& !$a3) { $node->content['flattr'] = array( '#value' => theme('flattr_button', $node, $account), '#weight' => module_exists('content') ? content_extra_field_weight($node->type, 'flattr') : -10, @@ -128,7 +209,7 @@ function flattr_theme($existing, $type, $theme, $path) { return array( 'flattr_button' => array( - 'arguments' => array('node' => NULL, 'account' => NULL), + 'arguments' => array('node' => NULL, 'account' => NULL, 'button' => NULL, 'id_suffix' => NULL), ), ); } @@ -136,15 +217,37 @@ /** * Themeable flattr button */ -function theme_flattr_button($node, $account) { +function theme_flattr_button($node, $account, $button, $id_suffix) { + + // Use the sitewide account till overriden + $flattr_uid = variable_get('flattr_sitewide_account', 'drupal'); + + // If override or per user only, override the sitewide account + if ($account->flattr['uid'] AND variable_get('flattr_sitewide_useage', 2)) { + $flattr_uid = check_plain($account->flattr['uid']); + } + drupal_add_css(drupal_get_path('module', 'flattr') . '/flattr.css'); - $output = '
'; + + // Ugly, but not sure how else to do it as D6 doesn't support 'external' js from drupal_add_js(); + global $flattr_script_added; + if (!$flattr_script_added) { + drupal_set_html_head(''); + $flattr_script_added = TRUE; + } + + $id = 'flattr-box'.($id_suffix?'-'.$id_suffix:''); + + $output = '
'; + + // Javascript Manual mode $output .= '" . "\n"; - $output .= '' . "\n"; - $output .= '
'; + + $output .= ' }, \''.$id.'\', \'replace\');'. "\n"; + + $output .= "});"; + + $output .= "\n"; return $output; }