'admin/settings/diggthis', 'title' => t('Diggthis'), 'description' => t('Enable the node types and set the properties for the diggthis button.'), 'callback' => 'drupal_get_form', 'callback arguments' => array('diggthis_admin_settings'), 'access' => user_access('administer site configuration'), 'type' => MENU_NORMAL_ITEM ); return $items; } /** * admin settings for the diggthis module */ function diggthis_admin_settings() { $form = array(); $form['diggthis'] = array( '#type' => 'fieldset', '#title' => 'diggthis ' . t('settings') ); $form['diggthis']['diggthis_button_skin'] = array( '#type' => 'select', '#title' => t('Button skin'), '#default_value' => variable_get('diggthis_button_skin', 'standard'), '#options' => array( 'standard' => t('standard'), 'compact' => t('compact') ), '#description' => t('The Button skin option controls the look at the button. If set to standard the button defaults to a standard digg button (much like the one you see on Digg itself). If specified as compact, then a smaller horizontal visual design is used that will fit better into a list of links.') ); $form['diggthis']['diggthis_button_bgcolor'] = array( '#type' => 'textfield', '#title' => t('Button background color'), '#default_value' => variable_get('diggthis_button_bgcolor', ''), '#size' => 7, '#maxlength' => 7, '#description' => t('Enter a hexadecimal color value here, e.g. #ff9900. Include the leading # and enter 6 numbers/digits') ); $form['diggthis']['diggthis_button_weight'] = array( '#type' => 'select', '#title' => t('Weight'), '#default_value' => variable_get('diggthis_button_weight', 10), '#options' => drupal_map_assoc(range(-20,20)), '#description' => t('Specifies the position of the Diggthis button. A low weight, e.g. -20 will display the button above the content and a high weight, e.g. 20 below the content.') ); $form['diggthis']['diggthis_node_types'] = array( '#type' => 'checkboxes', '#title' => t('Node Types'), '#default_value' => variable_get('diggthis_node_types', array()), '#options' => node_get_types('names'), '#description' => t('activate the node types in where the digg button shall be displayed') ); return system_settings_form($form); } /** * Implementation of hook_nodeapi(). */ function diggthis_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) { // we're in full node view if ($op == 'view' && !$a3) { if (in_array($node->type, variable_get('diggthis_node_types', array()), TRUE )) { $node->content['diggthis_button'] = array( '#value' => theme('diggthis_button', $node), '#weight' => variable_get('diggthis_button_weight', 10) ); } } } /** * theme function for button display */ function theme_diggthis_button($node) { // add diggthis css file $module_path = drupal_get_path('module','diggthis'); drupal_add_css($module_path . '/diggthis.css'); // absolute url of the current node $url = url('node/'. $node->nid, NULL, NULL, TRUE); // remove unwanted chars and markup $title = check_plain($node->title); $teaser = strip_tags($node->teaser); // make sure strings are not to long $title = truncate_utf8($title, 60, TRUE, FALSE); $teaser = drupal_to_js(truncate_utf8($teaser, 350, TRUE, FALSE)); // only set the background color if set $bgcolor = variable_get('diggthis_button_bgcolor', ''); if ($bgcolor) { $bg_string = "digg_bgcolor = '$bgcolor';"; } $skin = variable_get('diggthis_button_skin', 'standard'); $digg_js =<< EOF; return '
'. $digg_js .'
'; }