'FB Like Button', 'description' => 'Configure Facebook Like button settings.', 'page callback' => 'drupal_get_form', 'page arguments' => array('fblikebutton_admin_settings'), 'access arguments' => array('administer site configuration'), 'type' => MENU_NORMAL_ITEM, 'file' => 'fblikebutton.admin.inc', ); return $items; } /** * Implementation of hook_form_alter(). */ function fblikebutton_form_alter(&$form, &$form_state, $form_id){ if($form_id == "locale_languages_edit_form"){ $form['fblikebutton_language_code'] = array( '#type' => 'textfield', '#title' => t('Facebook Like Language Code'), '#default_value' => variable_get('fblikebutton_locale_language_' . $form['langcode']['#value'], ''), '#weight' => 0, ); $form['#submit'][] = 'fblikebutton_locale_languages_edit_form_submit'; } } function fblikebutton_locale_languages_edit_form_submit($form, &$form_state) { $values = $form_state['values']; variable_set('fblikebutton_locale_language_' . $values['langcode'], $values['fblikebutton_language_code']); } /** * Implementation of hook_nodeapi(). */ function fblikebutton_nodeapi(&$node, $op, $teaser, $page) { global $user, $base_url, $language; $likebase = $base_url . '/'; $likepath = drupal_get_path_alias($node->path); $webpage_to_like = $likebase . $likepath; switch ($op) { case 'view': // Set which node types users can "like". $types_to_like = variable_get('fblikebutton_node_types', array('page')); // Whether or not to show the faces of people who have "liked" the node. $show_faces = variable_get('fblikebutton_show_faces', 'true'); // Color scheme of the box. Options: "light" or "dark". $colorscheme = variable_get('fblikebutton_color_scheme', 'light'); // Layout style. Options: "Standard", "Box Count", or "Button Count". $layout = variable_get('fblikebutton_layout', 'standard'); // Action to display. Options: "Like" or "Recommend" $action = variable_get('fblikebutton_action', 'like'); // Font to use. $font = variable_get('fblikebutton_font', 'arial'); // Iframe height. $iframe_h = variable_get('fblikebutton_iframe_height', '80'); // Iframe width. $iframe_w = variable_get('fblikebutton_iframe_width', '450'); // Extra CSS to be tacked on to the end of the iframe. Example: padding-left: 5px; padding-top: 10px; $other_css = variable_get('fblikebutton_iframe_css', ''); $other_css = trim($other_css); // Load the language code $lang = variable_get('fblikebutton_locale_language_' . $language->language, 'en'); // The next part is whether or not to display the "Send" button next to the "Like" (or "Recommend") button. // CURRENTLY ONLY WORKS WITH XFBML (NOT IFRAME)... But it doesn't hurt anything and WILL // be in one of the next stable releases, so I'm leaving it there in case FB decides to enable // the feature to work with the iframe version. Until then, or until next stable release, see dev snapshot // if you require the "Send" button. $displaysend = variable_get('fblikebutton_send', 'true'); // Since we're currently using the iframe version... $likebutton = ''; // Keep the fblikebutton button out of search results, teasers, etc., if set. $fblikebutton_showonteasers = variable_get('fblikebutton_showonteasers', 0); if ($fblikebutton_showonteasers == 0) { if (!$page) { break; } } // Do not add the like button to any of the unchecked node types. if (!in_array($node->type, $types_to_like, TRUE)) { break; } // Check permissions, declare weight: if (user_access('users may access Like button')) { $likebutton_weight = variable_get('fblikebutton_weight', '0'); // If set, keep the button out of teasers: if ($fblikebutton_showonteasers == 0) { if ($teaser) { break; } } $node->content['fblikebutton_button'] = array( '#value' => $likebutton, '#weight' => $likebutton_weight, ); break; } } } /** * Implementation of hook_perm(). */ function fblikebutton_perm() { return array('users may administer Like button', 'users may administer Like button block', 'users may access Like button'); } /** * Implementation of hook_block(). */ function fblikebutton_block($op = 'list', $delta = 0, $edit = array()) { switch ($op) { case 'list': $blocks[0]['info'] = t('FB Like Button'); $blocks[0]['cache'] = BLOCK_NO_CACHE; return $blocks; case 'configure': global $base_url; if ($delta == 0 && user_access('users may administer Like button block')) { $form['fblikebutton_block_url'] = array( '#title' => t('URL to display'), '#type' => 'textfield', '#default_value' => variable_get('fblikebutton_block_url', $base_url), '#description' => t('URL of the webpage to like (default is the base URL of this site: @site). This value will remain the same throughout your site.', array('@site' => $base_url)) ); $form['fblikebutton_block'] = array( '#type' => 'fieldset', '#title' => 'Block configuration', '#collapsible' => false, ); $form['fblikebutton_block']['fblikebutton_bl_layout'] = array( '#type' => 'select', '#title' => t('Layout style'), '#options' => array('standard' => t('Standard'), 'box_count' => t('Box Count'), 'button_count' => t('Button Count')), '#default_value' => variable_get('fblikebutton_bl_layout', 'standard'), '#description' => t('Determines the size and amount of social context next to the button.'), ); $form['fblikebutton_block']['fblikebutton_bl_show_faces'] = array( '#type' => 'select', '#title' => t('Display faces in the box'), '#options' => array('show' => t('Show faces'), 'hide' => t('Do not show faces')), '#default_value' => variable_get('fblikebutton_bl_show_faces', 'show'), '#description' => t('Show profile pictures below the button. Only works if Layout style found above is set to Standard (otherwise, value is ignored).'), ); $form['fblikebutton_block']['fblikebutton_bl_action'] = array( '#type' => 'select', '#title' => t('Verb to display'), '#options' => array('like' => t('Like'), 'recommend' => t('Recommend')), '#default_value' => variable_get('fblikebutton_bl_action', 'like'), '#description' => t('The verbiage to display inside the button itself.'), ); $form['fblikebutton_block']['fblikebutton_bl_font'] = array( '#type' => 'select', '#title' => t('Font'), '#options' => array('arial' => 'Arial', 'lucida+grande' => 'Lucida Grande', 'segoe+ui' => 'Segoe UI', 'tahoma' => 'Tahoma', 'trebuchet+ms' => 'Trebuchet MS', 'verdana' => 'Verdana'), '#default_value' => variable_get('fblikebutton_bl_font', 'arial'), '#description' => t('The font with which to display the text of the button.'), ); $form['fblikebutton_block']['fblikebutton_bl_color_scheme'] = array( '#type' => 'select', '#title' => t('Color scheme'), '#options' => array('light' => t('Light'), 'dark' => t('Dark')), '#default_value' => variable_get('fblikebutton_bl_color_scheme', 'light'), '#description' => t('The color scheme of the box environtment.'), ); } return $form; case 'save': if ($delta == 0) { _pr($edit); variable_set('fblikebutton_block_url', $edit['fblikebutton_block_url']); variable_set('fblikebutton_bl_layout', $edit['fblikebutton_bl_layout']); variable_set('fblikebutton_bl_show_faces', $edit['fblikebutton_bl_show_faces']); variable_set('fblikebutton_bl_action', $edit['fblikebutton_bl_action']); variable_set('fblikebutton_bl_font', $edit['fblikebutton_bl_font']); variable_set('fblikebutton_bl_color_scheme', $edit['fblikebutton_bl_color_scheme']); } break; case 'view': global $base_url, $language; $addr = variable_get('fblikebutton_block_url', $base_url); $conf = array( 'layout' => variable_get('fblikebutton_bl_layout', "standard"), 'action' => variable_get('fblikebutton_bl_action', "like"), 'color_scheme' => variable_get('fblikebutton_bl_color_scheme', "light"), 'show_faces' => variable_get('fblikebutton_bl_show_faces', "false"), 'font' => variable_get('fblikebutton_bl_font', "arial"), 'lang' => variable_get('fblikebutton_locale_language_' . $language->language, 'en'), ); if (user_access('users may access Like button')) { $block['subject'] = t(''); $block['content'] = _fblikebutton_field($addr, $conf); return $block; } } } function _fblikebutton_field($addr, $conf) { $addr = urlencode($addr); $width = "100%"; $layout = $conf['layout']; $action = $conf['action']; $colorscheme = $conf['color_scheme']; $show_faces = $conf['show_faces']; $font = $conf['font']; $lang = $conf['lang']; switch ($layout) { case "box_count": $height = 65; break; case "button_count": $height = 21; break; case "standard": default: $height = $show_faces == "false" ? 35 : 80; break; } $params = "href=$addr&layout=$layout&show_faces=false&width&font=$font&height=$height&action=$action&colorscheme=$colorscheme&locale=$lang"; $src = htmlentities($params); $output = ""; return $output; }