Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- define('FBLIKE_IN_TEASER', 1);
- define('FBLIKE_IN_FULL', 2);
- define('FBLIKE_IN_BOTH', 3);
- function fblike_perm() {
- return array('access fblike', 'administer fblike');
- }
- function fblike_menu() {
- $items['admin/settings/fblike'] = array(
- 'title' => 'Facebook like',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('fblike_settings_form'),
- 'access arguments' => array('administer fblike'),
- );
- return $items;
- }
- function fblike_settings_form($form_state) {
- $form = array();
- $form['fblike_layout'] = array(
- '#type' => 'select',
- '#title' => t('Layout Style'),
- '#default_value' => variable_get('fblike_layout', 'standard'),
- '#options' => array('standard' => t('Standard'), 'button_count' => t('Button count')),
- );
- $form['fblike_faces'] = array(
- '#type' => 'checkbox',
- '#title' => t('Show faces'),
- '#default_value' => variable_get('fblike_faces', '1'),
- );
- $form['fblike_color'] = array(
- '#type' => 'select',
- '#title' => t('Color schema'),
- '#default_value' => variable_get('fblike_color', 'light'),
- '#options' => array('light' => t('Light'), 'dark' => t('Dark')),
- );
- $node_type_options = array();
- $node_types = node_get_types();
- foreach ($node_types as $type) {
- $node_type_options[$type->type] = $type->name;
- }
- $form['fblike_node_type'] = array(
- '#type' => 'select',
- '#title' => t('Node type'),
- '#default_value' => variable_get('fblike_node_type', array()),
- '#options' => $node_type_options,
- '#multiple' => TRUE,
- );
- $form['fblike_visibility'] = array(
- '#type' => 'select',
- '#title' => t('Visibility'),
- '#default_value' => variable_get('fblike_visibility', FBLIKE_IN_FULL),
- '#options' => array(
- FBLIKE_IN_TEASER => t('Teaser view'),
- FBLIKE_IN_FULL => t('Full-page view'),
- FBLIKE_IN_BOTH => t('Teasers and full-page view'),
- ),
- );
- $form['fblike_weight'] = array(
- '#type' => 'select',
- '#title' => t('Position'),
- '#default_value' => variable_get('fblike_weight', 100),
- '#options' => array(
- -100 => t('Top'),
- 100 => t('Bottom'),
- ),
- );
- return system_settings_form($form);
- }
- function fblike_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
- if (user_access('access fblike')) {
- switch ($op) {
- case 'view':
- if (in_array($node->type, variable_get('fblike_node_type', array()))) {
- $visible = FALSE;
- switch (variable_get('fblike_visibility', FBLIKE_IN_FULL)) {
- case FBLIKE_IN_TEASER:
- if ($teaser) {
- $visible = TRUE;
- }
- break;
- case FBLIKE_IN_FULL:
- if ($page) {
- $visible = TRUE;
- }
- break;
- case FBLIKE_IN_BOTH:
- if ($teaser || $page) {
- $visible = TRUE;
- }
- break;
- }
- if ($visible) {
- $options = array(
- 'absolute' => TRUE,
- 'alias' => FALSE,
- );
- $node_url = urlencode(url('node/'. $node->nid, $options));
- $node->content['content'] = array(
- '#value' => theme('fblike_frame', $node_url),
- '#weight' => variable_get('fblike_weight', 100),
- );
- drupal_set_html_head('<meta property="og:title" content="'. check_plain($node->title) .'"/>');
- drupal_set_html_head('<meta property="og:site_name" content="'. check_plain(variable_get('site_name', '')) .'"/>');
- }
- }
- break;
- }
- }
- }
- function fblike_theme() {
- return array(
- 'fblike_frame' => array(
- 'arguments' => array('url' => NULL),
- ),
- );
- }
- function theme_fblike_frame($url) {
- $layout = variable_get('fblike_layout', 'standard');
- $faces = variable_get('fblike_faces', '1') ? 'true' : 'false';
- $color = variable_get('fblike_color', 'light');
- $output = '<iframe src="http://www.facebook.com/plugins/like.php?href='. $url .'&layout='. $layout .'&show_faces='. $faces .'&width=450&action=like&colorscheme='. $color .'" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:100%; height:30px"></iframe>';
- return $output;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement