Guest User

fblike drupal module full

a guest
Dec 8th, 2010
335
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. define('FBLIKE_IN_TEASER', 1);
  4. define('FBLIKE_IN_FULL', 2);
  5. define('FBLIKE_IN_BOTH', 3);
  6.  
  7. function fblike_perm() {
  8.   return array('access fblike', 'administer fblike');
  9. }
  10.  
  11. function fblike_menu() {
  12.   $items['admin/settings/fblike'] = array(
  13.     'title' => 'Facebook like',
  14.     'page callback' => 'drupal_get_form',
  15.     'page arguments' => array('fblike_settings_form'),
  16.     'access arguments' => array('administer fblike'),
  17.   );
  18.   return $items;
  19. }
  20.  
  21. function fblike_settings_form($form_state) {
  22.  
  23.   $form = array();
  24.   $form['fblike_layout'] = array(
  25.     '#type' => 'select',
  26.     '#title' => t('Layout Style'),
  27.     '#default_value' => variable_get('fblike_layout', 'standard'),
  28.     '#options' => array('standard' => t('Standard'), 'button_count' => t('Button count')),
  29.   );
  30.   $form['fblike_faces'] = array(
  31.     '#type' => 'checkbox',
  32.     '#title' => t('Show faces'),
  33.     '#default_value' => variable_get('fblike_faces', '1'),
  34.   );
  35.   $form['fblike_color'] = array(
  36.     '#type' => 'select',
  37.     '#title' => t('Color schema'),
  38.     '#default_value' => variable_get('fblike_color', 'light'),
  39.     '#options' => array('light' => t('Light'), 'dark' => t('Dark')),
  40.   );
  41.   $node_type_options = array();
  42.   $node_types = node_get_types();
  43.   foreach ($node_types as $type) {
  44.     $node_type_options[$type->type] = $type->name;
  45.   }
  46.   $form['fblike_node_type'] = array(
  47.     '#type' => 'select',
  48.     '#title' => t('Node type'),
  49.     '#default_value' => variable_get('fblike_node_type', array()),
  50.     '#options' => $node_type_options,
  51.     '#multiple' => TRUE,
  52.   );
  53.   $form['fblike_visibility'] = array(
  54.     '#type' => 'select',
  55.     '#title' => t('Visibility'),
  56.     '#default_value' => variable_get('fblike_visibility', FBLIKE_IN_FULL),
  57.     '#options' => array(
  58.       FBLIKE_IN_TEASER => t('Teaser view'),
  59.       FBLIKE_IN_FULL => t('Full-page view'),
  60.       FBLIKE_IN_BOTH => t('Teasers and full-page view'),
  61.     ),
  62.   );
  63.   $form['fblike_weight'] = array(
  64.     '#type' => 'select',
  65.     '#title' => t('Position'),
  66.     '#default_value' => variable_get('fblike_weight', 100),
  67.     '#options' => array(
  68.       -100 => t('Top'),
  69.       100 => t('Bottom'),
  70.     ),
  71.   );
  72.  
  73.   return system_settings_form($form);
  74. }
  75.  
  76. function fblike_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
  77.   if (user_access('access fblike')) {
  78.     switch ($op) {
  79.       case 'view':
  80.         if (in_array($node->type, variable_get('fblike_node_type', array()))) {
  81.           $visible = FALSE;
  82.           switch (variable_get('fblike_visibility', FBLIKE_IN_FULL)) {
  83.             case FBLIKE_IN_TEASER:
  84.               if ($teaser) {
  85.                 $visible = TRUE;
  86.               }
  87.             break;
  88.            
  89.             case FBLIKE_IN_FULL:
  90.               if ($page) {
  91.                 $visible = TRUE;
  92.               }
  93.             break;
  94.            
  95.             case FBLIKE_IN_BOTH:
  96.               if ($teaser || $page) {
  97.                 $visible = TRUE;
  98.               }
  99.             break;
  100.           }
  101.           if ($visible) {
  102.             $options = array(
  103.               'absolute' => TRUE,
  104.               'alias' => FALSE,
  105.             );
  106.             $node_url = urlencode(url('node/'. $node->nid, $options));
  107.             $node->content['content'] = array(
  108.               '#value' => theme('fblike_frame', $node_url),
  109.               '#weight' => variable_get('fblike_weight', 100),
  110.             );
  111.             drupal_set_html_head('<meta property="og:title" content="'. check_plain($node->title) .'"/>');
  112.             drupal_set_html_head('<meta property="og:site_name" content="'. check_plain(variable_get('site_name', '')) .'"/>');
  113.           }
  114.         }
  115.       break;
  116.     }
  117.   }
  118. }
  119.  
  120. function fblike_theme() {
  121.  return array(
  122.     'fblike_frame' => array(
  123.       'arguments' => array('url' => NULL),
  124.     ),
  125.   );
  126. }
  127.  
  128. function theme_fblike_frame($url) {
  129.   $layout = variable_get('fblike_layout', 'standard');
  130.   $faces = variable_get('fblike_faces', '1') ? 'true' : 'false';
  131.   $color = variable_get('fblike_color', 'light');
  132.   $output = '<iframe src="http://www.facebook.com/plugins/like.php?href='. $url .'&amp;layout='. $layout .'&amp;show_faces='. $faces .'&amp;width=450&amp;action=like&amp;colorscheme='. $color .'" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:100%; height:30px"></iframe>';
  133.   return $output;
  134. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×