Changeset 8420


Ignore:
Timestamp:
Jan 1, 2011, 11:16:52 AM (10 years ago)
Author:
rub
Message:

Facebook_Integration plugin is inactivated when FacebookPlug is activating
Get representative image for category or random picture (and not only first picture)
Allow Facebook to access private index page

Location:
extensions/FacebookPlug/Plugin
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • extensions/FacebookPlug/Plugin/include/header.inc.php

    r8402 r8420  
    119119  ;
    120120}
    121 add_event_handler('fbp_do_facebook_init', 'fbp_do_facebook_init');
     121
     122function fbp_is_facebook_ip()
     123{
     124  foreach (array(
     125    FBP_IP_FB,
     126    //~ '127.0',
     127      ) as $ip_fb)
     128  {
     129    if (preg_match('/'.$ip_fb. '/', $_SERVER["REMOTE_ADDR"]))
     130    {
     131      return true;
     132    }
     133  }
     134  return false;
     135}
     136
     137function ftp_loc_end_section_init()
     138{
     139  global $conf, $page, $user;
     140
     141  // No restristion for facebook user
     142  if (
     143      $page['fbp']['do_facebook_init']
     144      and
     145      is_a_guest()
     146      and
     147      $conf['fbp']['allow_fb_access_private_page']
     148      and
     149      fbp_is_facebook_ip()
     150    )
     151  {
     152    global $user, $header_notes;
     153
     154    // Notes
     155    $header_notes[] = 'Facebook robot detected, guest can access private page';
     156    // Allow guest access
     157    $conf['guest_access'] = true;
     158    // No forbidden categorie
     159    $user['forbidden_categories'] = '';
     160    $user['level'] = max($conf['available_permission_levels']);
     161    switch (script_basename())
     162    {
     163      case 'picture':
     164        if (isset($page['image_id']))
     165        {
     166          $page['rank_of'][$page['image_id']] = 0;
     167          $page['items'] = array_flip($page['rank_of']);
     168        }
     169        break;
     170      case 'index':
     171        if (isset($page['category']['representative_picture_id']))
     172        {
     173          fbp_loc_begin_index_category_thumbnails(array($page['category']));
     174        }
     175      break;
     176    }
     177    //~ else if $page['category']['id']
     178  }
     179}
    122180
    123181add_event_handler('init', 'fbp_init');
    124182add_event_handler('loc_end_page_header', 'fbp_loc_end_page_header');
     183add_event_handler('fbp_do_facebook_init', 'fbp_do_facebook_init');
     184add_event_handler('loc_end_section_init', 'ftp_loc_end_section_init');
    125185
    126186?>
  • extensions/FacebookPlug/Plugin/include/index.inc.php

    r8402 r8420  
    8282  global $page;
    8383
    84   if (count($categories) > 0)
     84  $C = count($categories);
     85  if ($C > 0)
    8586  {
    8687    include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php');
    87     $category = reset($categories);
    88     $query = '
     88    //~ $category = reset($categories);
     89    $category = $categories[rand(0, $C-1)];
     90    if (is_numeric($category['representative_picture_id']))
     91    {
     92      $query = '
    8993SELECT id, path, tn_ext
    9094FROM '.IMAGES_TABLE.'
    9195WHERE id = '.$category['representative_picture_id'].'
    9296;';
    93     $result = pwg_query($query);
    94     if($row = pwg_db_fetch_assoc($result))
    95     {
    96       set_make_full_url();
    97       $page['fbp']['url_image'] = get_thumbnail_url($row);
    98       unset_make_full_url();
     97      $result = pwg_query($query);
     98      if($row = pwg_db_fetch_assoc($result))
     99      {
     100        set_make_full_url();
     101        $page['fbp']['url_image'] = get_thumbnail_url($row);
     102        unset_make_full_url();
     103      }
    99104    }
    100105  }
     
    105110  global $page;
    106111
    107   if (count($pictures) > 0)
     112  if (isset($page['category']['representative_picture_id']))
    108113  {
    109     include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php');
    110     $picture = reset($pictures);
    111     set_make_full_url();
    112     $page['fbp']['url_image'] = get_thumbnail_url($picture);
    113     unset_make_full_url();
     114    fbp_loc_begin_index_category_thumbnails(array($page['category']));
     115  }
     116  else
     117  {
     118    $C = count($pictures);
     119    if ($C > 0)
     120    {
     121      include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php');
     122      $picture = reset($pictures);
     123      $picture = $pictures[rand(0, $C-1)];
     124      set_make_full_url();
     125      $page['fbp']['url_image'] = get_thumbnail_url($picture);
     126      unset_make_full_url();
     127    }
    114128  }
    115129}
  • extensions/FacebookPlug/Plugin/include/picture.inc.php

    r8402 r8420  
    9090}
    9191
    92 function ftp_loc_end_section_init()
    93 {
    94   global $conf, $page;
    95 
    96   //~ if ($conf['fbp']['social_plugin_like_button']['enabled'] or $conf['fbp']['social_plugin_comments']['enabled'])
    97   if ($page['fbp']['do_facebook_init'])
    98   {
    99     if ($conf['fbp']['allow_fb_access_private_page'])
    100     {
    101       global $user, $page;
    102 
    103       // No restristion for facebook user
    104       if (preg_match('/'.FBP_IP_FB. '/', $_SERVER["REMOTE_ADDR"]))
    105       {
    106         //Allow guest access
    107         $conf['guest_access'] = true;
    108         // No forbidden categorie
    109         $user['forbidden_categories'] = '';
    110         $user['level'] = max($conf['available_permission_levels']);
    111         $page['rank_of'][$page['image_id']] = 0;
    112         $page['items'] = array_flip($page['rank_of']);
    113       }
    114     }
    115   }
    116 }
    117 
    11892add_event_handler('render_element_content', 'fbp_render_element_content', EVENT_HANDLER_PRIORITY_NEUTRAL+1 /*in order to have picture content*/, 2);
    119 add_event_handler('loc_end_section_init', 'ftp_loc_end_section_init');
    12093
    12194?>
  • extensions/FacebookPlug/Plugin/maintain.inc.php

    r8241 r8420  
    2626function plugin_install()
    2727{
     28  // Update configuration
    2829  $query = '
    2930replace into '.CONFIG_TABLE.'
     
    4041}
    4142
     43function plugin_activate()
     44{
     45  // Inactivate plugins
     46  $plugins = array('Facebook_Integration');
     47    $query = '
     48update '.PLUGINS_TABLE.'
     49set STATE=\'inactive\'
     50where ID in (\'' . implode('\',\'', $plugins) . '\')
     51;';
     52    pwg_query($query);
     53
     54}
     55
    4256function plugin_uninstall()
    4357{
     58  // Delete configuration
    4459  $query = '
    4560delete from '.CONFIG_TABLE.'
Note: See TracChangeset for help on using the changeset viewer.