Plugin Directory

Changeset 191361


Ignore:
Timestamp:
01/08/2010 02:54:38 AM (16 years ago)
Author:
aaron_guitar
Message:

Fixed bug where some accounts would only import the photos of the user

Location:
fotobook/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • fotobook/trunk/fotobook.php

    r167260 r191361  
    77Author: Aaron Harp
    88Author URI: http://www.aaronharp.com/
    9 Version: 3.1.7
     9Version: 3.1.8
    1010*/
    1111
    1212/*
    1313Copyright 2008 Aaron Harp
    14  
     14
    1515This program is free software: you can redistribute it and/or modify
    1616it under the terms of the GNU General Public License as published by
     
    4040define('FB_OPTIONS_URL', 'options-general.php?page=fotobook/options-fotobook.php');
    4141define('FB_WEBSITE',     'http://www.aaronharp.com/dev/wp-fotobook/');
    42 define('FB_VERSION',     3.17);
     42define('FB_VERSION',     3.18);
    4343define('FB_DONATE',      'https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=aaron%40freshwebs%2enet&item_name=Fotobook%20Donation&no_shipping=0&no_note=1&tax=0&currency_code=USD&lc=US&bn=PP%2dDonationsBF&charset=UTF%2d8');
    4444
     
    8080  var $msg      = null;
    8181  var $secret   = null;
    82  
     82
    8383  function FacebookAPI() {
    8484    if(version_compare('5', PHP_VERSION, "<=")) {
     
    8787      require_once('facebook-platform/php4client/facebook.php');
    8888    }
    89    
     89
    9090    $this->facebook   = new Facebook(FB_API_KEY, FB_API_SECRET, null, true);
    9191    $this->client = $this->facebook->api_client;
    92      
     92
    9393    global $fb_message;
    9494    $this->msg = &$fb_message;
    95            
    96     // check if the facebook session is the structure from older 
     95
     96    // check if the facebook session is the structure from older
    9797    // versions of Fotobook, if so remove it to start over
    9898    $sessions = get_option('fb_facebook_session');
     
    100100      update_option('fb_facebook_session', '');
    101101    }
    102                
     102
    103103    if(isset($_POST['activate-facebook'])) {
    104104      $this->get_auth_session($_POST['activate-facebook']);
     
    110110    if(isset($_GET['deactivate-facebook']) && isset($this->sessions[$_GET['deactivate-facebook']])) {
    111111      $this->remove_user($_GET['deactivate-facebook']);
    112     } 
    113    
     112    }
     113
    114114    // get token every time for additional users
    115     $this->token = $this->get_auth_token();     
    116    
     115    $this->token = $this->get_auth_token();
     116
    117117  }
    118118
     
    127127    if(!$this->token) {
    128128      $this->error = true;
    129       $this->msg = 'Fotobook is unable to connect to Facebook.  This is most likely due to your server not allowing requests to external servers.  For hosting that does support this, sign up for a <a href="http://www.dreamhost.com/r.cgi?275020/signup|fotobook">Dreamhost account</a> using the promo code "Fotobook" and you\'ll get a discount.'; 
     129      $this->msg = 'Fotobook is unable to connect to Facebook.  This is most likely due to your server not allowing requests to external servers.  For hosting that does support this, sign up for a <a href="http://www.dreamhost.com/r.cgi?275020/signup|fotobook">Dreamhost account</a> using the promo code "Fotobook" and you\'ll get a discount.';
    130130    }
    131131    return $this->token;
     
    134134  function get_sessions() {
    135135    $sessions = get_option('fb_facebook_session');
    136    
     136
    137137    // make sure all accounts are still active
    138138    if(!$sessions) return false;
     
    147147        unset($sessions[$key]);
    148148        update_option('fb_facebook_session',$sessions);
    149       }     
    150     }
    151    
     149      }
     150    }
     151
    152152    $this->sessions = $sessions;
    153153    return count($sessions) > 0;
     
    163163      $this->msg = 'Unable to activate account. [Error #'.$this->client->error_code.']';
    164164      return false;
    165     } 
    166      
     165    }
     166
    167167    // check to see if this account is already linked
    168168    $active = array();
     
    174174      return false;
    175175    }
    176    
     176
    177177    // get user's name
    178178    $this->client->session_key = $new_session['session_key'];
     
    180180    $user = $this->client->users_getInfo($new_session['uid'], array('name'));
    181181    $new_session['name'] = $user[0]['name'];
    182     //if(!$new_session['name']) 
     182    //if(!$new_session['name'])
    183183      //return false;
    184184    if(!is_array($sessions)) $sessions = array();
     
    188188    return count($sessions) > 0;
    189189  }
    190  
     190
    191191  function remove_user($key) {
    192192    // remove all of this user's albums and photos
    193193    global $wpdb;
    194    
     194
    195195    $albums = fb_get_album(0, $this->sessions[$key]['uid']);
    196196    if(is_array($albums)) {
     
    199199      }
    200200    }
    201    
     201
    202202    $wpdb->query('DELETE FROM '.FB_ALBUM_TABLE.' WHERE owner = '.$this->sessions[$key]['uid']);
    203203    $wpdb->query('DELETE FROM '.FB_PHOTO_TABLE.' WHERE owner = '.$this->sessions[$key]['uid']);
    204    
     204
    205205    $this->msg = 'The link to '.$this->sessions[$key]['name'].'\'s Facebook account has been removed.';
    206    
     206
    207207    unset($this->sessions[$key]);
    208     update_option('fb_facebook_session', $this->sessions);   
    209   }
    210  
     208    update_option('fb_facebook_session', $this->sessions);
     209  }
     210
    211211  function update_progress($increment) {
    212212    if($increment == -1) {
    213213      $progress = 0;
    214214    } else {
    215       $progress = get_option('fb_update_progress') + $increment;     
     215      $progress = get_option('fb_update_progress') + $increment;
    216216    }
    217217    if($progress > 100)
     
    220220    return $progress;
    221221  }
    222  
     222
    223223  function update_albums() {
    224224    global $wpdb;
    225    
     225
    226226    // allow the script plenty of time to make requests
    227227    if(!ini_get('safe_mode') && !strstr(ini_get('disabled_functions'), 'set_time_limit'))
    228228      set_time_limit(500);
    229    
     229
    230230    // reset album import progress
    231231    update_option('fb_update_progress', 0);
    232232
    233233    // if this is the first import then reset the order at the end to make the newest on top
    234     $reset_order = count(fb_get_album()) > 0 ? false : true;   
    235    
     234    $reset_order = count(fb_get_album()) > 0 ? false : true;
     235
    236236    // determine how much to increment the progress bar after each request
    237237    $incr = 100 / (count($this->sessions) * 3);
    238        
     238
    239239    // get albums for each user from Facebook
    240240    $fb_albums = array(); $fb_photos = array();
     
    244244      $this->client->session_key = $session['session_key'];
    245245      $this->client->secret = $session['secret'];
    246      
     246
    247247      // get all albums
    248248      $result = $this->client->photos_getAlbums($uid, null);
    249249      if(!is_array($result)) // if the current user has no photos so move on
    250250        continue;
    251       $fb_albums = array_merge($fb_albums, $result);   
     251      $fb_albums = array_merge($fb_albums, $result);
    252252      $this->update_progress($incr);
    253      
     253
    254254      // get all photos
    255255      $fb_photos = array_merge($fb_photos, (array)$this->client->fql_query("SELECT pid, aid, owner, src, src_big, src_small, link, caption, created FROM photo WHERE aid IN (SELECT aid FROM album WHERE owner = $uid)"));
    256256      $this->update_progress($incr);
    257      
     257
    258258      // get photos of user
    259259      $fb_user_photos = $this->client->photos_get($uid, null, null);
     
    262262        $fb_photos = array_merge($fb_photos, (array)$fb_user_photos);
    263263        $fb_albums[] = array(
    264           'aid'=>$uid, 
    265           'cover_pid'=>$fb_user_photos[0]['pid'], 
    266           'owner'=>$uid, 
    267           'name'=>'Photos of '.(count($this->sessions) > 1 ? $session['name'] : 'Me'), 
    268           'created'=>time(), 
    269           'modified'=>time(), 
    270           'description'=>'', 
    271           'location'=>'', 
    272           'link'=>"http://www.facebook.com/photo_search.php?id=$uid", 
     264          'aid'=>$uid,
     265          'cover_pid'=>$fb_user_photos[0]['pid'],
     266          'owner'=>$uid,
     267          'name'=>'Photos of '.(count($this->sessions) > 1 ? $session['name'] : 'Me'),
     268          'created'=>time(),
     269          'modified'=>time(),
     270          'description'=>'',
     271          'location'=>'',
     272          'link'=>"http://www.facebook.com/photo_search.php?id=$uid",
    273273          'size'=>count($fb_user_photos)
    274274        );
    275275      }
    276      
     276
    277277      if(!$fb_albums || $this->client->error_code) {
    278278        $this->msg   = 'Fotobook encountered an error while retrieving your photos. [Error #'.$this->client->error_code.']';
    279279        return false;
    280280      }
    281            
    282     }
    283                
    284     // put all the albums in an array with the aid as the key 
     281
     282    }
     283
     284    // put all the albums in an array with the aid as the key
    285285    $albums = fb_get_album();
    286286    if($albums) {
     
    288288        $wp_albums[$album['aid']] = $album;
    289289      }
    290     }   
    291      
     290    }
     291
    292292    // go through all the facebook albums see which ones need to be added
    293293    foreach($fb_albums as $album) {
    294294      $wp_album = isset($wp_albums[$album['aid']]) ? $wp_albums[$album['aid']] : false;
    295    
    296       // create or update the WP page     
     295
     296      // create or update the WP page
    297297      if($wp_album) {
    298298        $hidden  = $wp_album['hidden'];
     
    302302          if($album['name'] != $wp_album['name']) {
    303303            fb_update_page($page_id, $album['name']);
    304           }       
     304          }
    305305        } else {
    306           $page_id = fb_add_page($album['name']); 
     306          $page_id = fb_add_page($album['name']);
    307307        }
    308308      } else {
     
    311311        $ordinal = fb_get_next_ordinal();
    312312      }
    313      
     313
    314314      // if updating, remove from database first
    315       $wpdb->query('DELETE FROM '.FB_ALBUM_TABLE.' WHERE aid = '.$album['aid']);
    316    
     315      $wpdb->query("DELETE FROM ".FB_ALBUM_TABLE." WHERE aid = '".$album['aid']."'");
     316
    317317      // add album to database
    318318      if(!get_magic_quotes_runtime()) {
    319319        $album['name'] = addslashes($album['name']);
    320320        $album['description'] = addslashes($album['description']);
    321         $album['location'] = addslashes($album['location']);       
     321        $album['location'] = addslashes($album['location']);
    322322      }
    323323      $album_query = sprintf("INSERT INTO %s SET page_id='%s', aid='%s', cover_pid='%s', owner='%s', name='%s', created=FROM_UNIXTIME(%s), modified=FROM_UNIXTIME(%s), description='%s', location='%s', link='%s', size='%s', hidden='%s', ordinal='%s'",
    324                             FB_ALBUM_TABLE, $page_id, $album['aid'], $album['cover_pid'], $album['owner'], $album['name'], $album['created'], $album['modified'], $album['description'], $album['location'], $album['link'], $album['size'], $hidden, $ordinal); 
    325       $wpdb->query($album_query);   
    326     }
    327    
     324                            FB_ALBUM_TABLE, $page_id, $album['aid'], $album['cover_pid'], $album['owner'], $album['name'], $album['created'], $album['modified'], $album['description'], $album['location'], $album['link'], $album['size'], $hidden, $ordinal);
     325      $wpdb->query($album_query);
     326    }
     327
    328328    // update the photos
    329329    $wpdb->query('DELETE FROM '.FB_PHOTO_TABLE);
     
    339339                             FB_PHOTO_TABLE, $photo['pid'], $photo['aid'], $photo['owner'], $photo['src'], $photo['src_big'], $photo['src_small'], $photo['link'], $photo['caption'], $photo['created'], $ordinal);
    340340      $wpdb->query($photo_query);
    341      
     341
    342342      // handle ordinal
    343343      $last_aid = $photo['aid'];
    344344      $ordinal++;
    345345    }
    346    
     346
    347347    // put IDs of all albums in an array
    348348    foreach($fb_albums as $album) {
    349       $album_ids[] = $album['aid'];         
    350     }
    351    
    352     $wp_albums = fb_get_album();   
     349      $album_ids[] = $album['aid'];
     350    }
     351
     352    $wp_albums = fb_get_album();
    353353    if(count($wp_albums) > 0) {
    354354      // delete albums that have been removed off of Facebook
     
    356356        if(!@in_array($album['aid'], $album_ids)) {
    357357          fb_delete_page($album['page_id']);
    358           $wpdb->query('DELETE FROM '.FB_ALBUM_TABLE.' WHERE aid = '.$album['aid']);
     358          $wpdb->query("DELETE FROM ".FB_ALBUM_TABLE." WHERE aid = '".$album['aid']."'");
    359359        }
    360360      }
    361      
     361
    362362      // delete superfluous pages
    363363      foreach($wp_albums as $album) {
     
    368368        if(!in_array($page['ID'], $album_pages)) {
    369369          fb_delete_page($page['ID']);
    370         } 
    371       }   
    372     }
    373    
     370        }
     371      }
     372    }
     373
    374374    // now reset the order if needed
    375375    if($reset_order) {
    376376      fb_reset_album_order();
    377377    }
    378    
     378
    379379    if(!$this->msg) {
    380       $this->msg = 'Albums imported successfully.';     
     380      $this->msg = 'Albums imported successfully.';
    381381    }
    382382    $this->update_progress(-1);
    383383  }
    384 } 
     384}
    385385
    386386//---------------------//
     
    390390function fb_initialize() {
    391391  global $wpdb;
    392  
     392
    393393  // add default options
    394394  add_option('fb_albums_page', 0);
     
    401401  add_option('fb_embedded_width', 0);
    402402  add_option('fb_hide_pages', 0);
    403        
     403
    404404  $photo_table_query = "CREATE TABLE ".FB_PHOTO_TABLE." (
    405405                          id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
    406                           pid bigint(20) unsigned NOT NULL,
    407                           aid bigint(20) unsigned NOT NULL default 0,
     406                          pid varchar(25) NOT NULL default '',
     407                          aid varchar(25) NOT NULL default '',
    408408                          owner bigint(20) NOT NULL default 0,
    409409                          src varchar(255) NOT NULL default '',
     
    418418
    419419  $album_table_query = "CREATE TABLE ".FB_ALBUM_TABLE." (
    420                           aid bigint(20) unsigned NOT NULL,
     420                          aid varchar(25) NOT NULL default '',
    421421                          page_id int(11) NOT NULL,
    422                           cover_pid bigint(20) NOT NULL,
     422                          cover_pid varchar(25) NOT NULL default '',
    423423                          owner int(11) NOT NULL,
    424424                          name varchar(255) NOT NULL default '',
     
    432432                          ordinal tinyint(4) NOT NULL default 0,
    433433                          UNIQUE KEY id (aid)
    434                         ) TYPE = MyISAM"; 
    435                        
    436   fb_upgrade_tables(); 
    437  
     434                        ) TYPE = MyISAM";
     435
     436  fb_upgrade_tables();
     437
    438438  if(!fb_table_exists(FB_PHOTO_TABLE)) {
    439439    $wpdb->query($photo_table_query);
    440440  }
    441  
     441
    442442  if(!fb_table_exists(FB_ALBUM_TABLE)) {
    443443    $wpdb->query($album_table_query);
    444444  }
    445  
     445
    446446  update_option('fb_version', FB_VERSION);
    447447}
     
    466466function fb_upgrade_tables() {
    467467  global $wpdb;
    468  
     468
    469469  // this is an upgrade from v1
    470470  if(fb_table_exists(FB_ALBUM_TABLE) && $wpdb->get_results('SHOW COLUMNS FROM '.FB_ALBUM_TABLE." WHERE Field = 'timecached'")) {
    471471    $wpdb->query('DROP TABLE '.FB_ALBUM_TABLE);
    472     $wpdb->query('DROP TABLE '.FB_PHOTO_TABLE); 
    473   }
    474  
     472    $wpdb->query('DROP TABLE '.FB_PHOTO_TABLE);
     473  }
     474
    475475  // this is an upgrade to fix the duplicate key issue
    476476  if(fb_table_exists(FB_PHOTO_TABLE) && !$wpdb->get_results('SHOW COLUMNS FROM '.FB_PHOTO_TABLE." WHERE Field = 'id'")) {
     
    480480  if(get_option('fb_version') < 3.17)
    481481    $wpdb->query('ALTER TABLE '.FB_PHOTO_TABLE.' CHANGE `caption` `caption` TEXT');
     482
     483  if(get_option('fb_version') < 3.18) {
     484    $wpdb->query("ALTER TABLE ".FB_PHOTO_TABLE." CHANGE `pid` `pid` varchar(25) NOT NULL DEFAULT ''");
     485    $wpdb->query("ALTER TABLE ".FB_PHOTO_TABLE." CHANGE `aid` `aid` varchar(25) NOT NULL DEFAULT ''");
     486    $wpdb->query("ALTER TABLE ".FB_ALBUM_TABLE." CHANGE `aid` `aid` varchar(25) NOT NULL DEFAULT ''");
     487    $wpdb->query("ALTER TABLE ".FB_ALBUM_TABLE." CHANGE `cover_pid` `cover_pid` varchar(25) NOT NULL DEFAULT ''");
     488  }
    482489}
    483490
     
    503510    'post_type'      => 'page',
    504511    'post_content'   => '',
    505     'post_title'     => $name, 
     512    'post_title'     => $name,
    506513    'post_status'    => 'publish',
    507514    'post_parent'    => get_option('fb_albums_page'),
     
    514521function fb_delete_page($id) {
    515522  if(fb_page_exists($id)) {
    516    
     523
    517524    // disable conflicting Wordbook action
    518525    remove_action('delete_post', 'wordbook_delete_post');
    519    
     526
    520527    wp_delete_post($id);
    521528  }
     
    524531function fb_update_page($id, $name, $hidden = false) {
    525532  global $wpdb;
    526    
     533
    527534  $parent = get_option('fb_albums_page');
    528535  $comment_status = get_option('fb_album_cmts') ? 'open' : 'closed';
     
    538545  );
    539546
    540   if(get_bloginfo('version') >= 2.1) { 
     547  if(get_bloginfo('version') >= 2.1) {
    541548    $array['post_status'] = 'publish';
    542549    $array['post_type']   = 'page';
     
    544551    $array['post_status'] = 'static';
    545552  }
    546  
     553
    547554  return wp_update_post($array);
    548555}
     
    567574    echo 'success';
    568575  }
    569  
     576
    570577  // handle order change
    571578  elseif(isset($_POST['order'])) {
     
    573580    echo 'success';
    574581  }
    575  
     582
    576583  // handle order reset
    577584  elseif(isset($_POST['reset_order'])) {
     
    579586    echo 'The albums have been ordered by their modification date.';
    580587  }
    581  
     588
    582589  // handle remove all
    583590  elseif(isset($_POST['remove_all'])) {
     
    585592    echo 'All albums have been removed.';
    586593  }
    587  
     594
    588595  // handle update progress request
    589596  elseif(isset($_POST['progress'])) {
    590597    echo round(get_option('fb_update_progress'));
    591598  }
    592  
     599
    593600  // handle update albums request
    594601  elseif(isset($_POST['update'])) {
     
    601608    }
    602609  }
    603  
     610
    604611  // handle albums list request
    605612  elseif(isset($_POST['albums_list'])) {
    606613    fb_display_manage_list($_POST['message']);
    607614  }
    608  
     615
    609616  exit;
    610617}
     
    612619function fb_options_update_albums_page($new_id) {
    613620  global $wpdb;
    614    
     621
    615622  $old_id = get_option('fb_albums_page');
    616623  if($old_id == $new_id) {
    617624    return true;
    618625  }
    619  
     626
    620627  $albums = fb_get_album();
    621628  if(sizeof($albums) > 0) {
     
    624631    }
    625632  }
    626  
    627   update_option('fb_albums_page', $new_id); 
     633
     634  update_option('fb_albums_page', $new_id);
    628635}
    629636
    630637function fb_options_toggle_comments($status = true) {
    631638  global $wpdb;
    632  
     639
    633640  if($status) $status = 'open';
    634641  else $status = 'closed';
    635  
     642
    636643  $fb_albums_page = get_option('fb_albums_page');
    637  
     644
    638645  $wpdb->query("UPDATE ".FB_POSTS_TABLE." SET comment_status='$status' WHERE post_parent = $fb_albums_page");
    639646}
     
    650657  if ($handle = opendir(FB_PLUGIN_PATH.'styles')) {
    651658    while (false !== ($file = readdir($handle))) {
    652       if(substr($file, 0, 1) != '.' && is_dir(FB_PLUGIN_PATH.'styles/'.$file)) 
     659      if(substr($file, 0, 1) != '.' && is_dir(FB_PLUGIN_PATH.'styles/'.$file))
    653660        $styles[] = $file;
    654661    }
     
    661668function fb_parent_dropdown( $default = 0, $parent = 0, $level = 0 ) {
    662669  global $wpdb;
    663  
     670
    664671  $albums_page = get_option('fb_albums_page');
    665  
     672
    666673  $items = $wpdb->get_results( "SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = $parent AND post_type = 'page' AND post_parent != $albums_page ORDER BY menu_order" );
    667674
     
    708715  $query = 'SELECT * FROM '.FB_ALBUM_TABLE.' ';
    709716  $where = '';
    710  
     717
    711718  if($album_id || $user_id || $displayed_only)
    712719    $query .= "WHERE ";
    713  
     720
    714721  if($album_id) {
    715     $query .= "aid = $album_id ";
     722    $query .= "aid = '$album_id' ";
    716723    $array = $wpdb->get_results($query, ARRAY_A);
    717724    return $array[0];
     
    725732    $where .= "hidden = 0 ";
    726733  }
    727        
     734
    728735  $query .= $where."ORDER BY ordinal DESC";
    729  
     736
    730737  $results = $wpdb->get_results($query, ARRAY_A);
    731  
     738
    732739  return $results;
    733740}
     
    742749  $order = array_reverse(explode(',', $order));
    743750  foreach($order as $key=>$value) {
    744     $wpdb->query('UPDATE '.FB_ALBUM_TABLE.' SET ordinal = '.$key.' WHERE aid = '.$value.' LIMIT 1');
     751    $wpdb->query("UPDATE ".FB_ALBUM_TABLE." SET ordinal = $key WHERE aid = '$value' LIMIT 1");
    745752  }
    746753}
     
    752759    return false;
    753760  foreach($albums as $key=>$album) {
    754     $wpdb->query('UPDATE '.FB_ALBUM_TABLE.' SET ordinal = '.$key.' WHERE aid = '.$album['aid']);
     761    $wpdb->query("UPDATE ".FB_ALBUM_TABLE." SET ordinal = $key WHERE aid = '".$album['aid']."'");
    755762  }
    756763  return true;
     
    779786function fb_toggle_album_hiding($id) {
    780787  global $wpdb;
    781   $old = $wpdb->get_var('SELECT hidden FROM '.FB_ALBUM_TABLE.' WHERE aid = '.$id);
     788  $old = $wpdb->get_var('SELECT hidden FROM '.FB_ALBUM_TABLE." WHERE aid = '$id'");
    782789  $new = ($old == 1) ? 0 : 1;
    783   $wpdb->query('UPDATE '.FB_ALBUM_TABLE.' SET hidden = '.$new.' WHERE aid = '.$id);
     790  $wpdb->query('UPDATE '.FB_ALBUM_TABLE.' SET hidden = '.$new." WHERE aid = '$id'");
    784791  return true;
    785792}
     
    789796
    790797  $query = 'SELECT * FROM '.FB_PHOTO_TABLE.' ';
    791   if($album_id != 0) $query .= "WHERE aid = $album_id ";
    792   $query .= "ORDER BY ordinal ASC"; 
     798  if($album_id != 0) $query .= "WHERE aid = '$album_id' ";
     799  $query .= "ORDER BY ordinal ASC";
    793800  $photos = $wpdb->get_results($query, ARRAY_A);
    794801
     
    799806  global $wpdb;
    800807  if(!is_numeric($id)) return false;
    801   $query = 'SELECT * FROM '.FB_PHOTO_TABLE.' WHERE pid = '.$id;
     808  $query = "SELECT * FROM ".FB_PHOTO_TABLE." WHERE pid = '$id'";
    802809  $photo = $wpdb->get_row($query, ARRAY_A);
    803810  switch ($size) {
     
    820827  global $wpdb;
    821828  $query = "SELECT ".FB_PHOTO_TABLE.".link, pid, src, src_big, src_small, caption
    822             FROM ".FB_PHOTO_TABLE.", ".FB_ALBUM_TABLE." 
     829            FROM ".FB_PHOTO_TABLE.", ".FB_ALBUM_TABLE."
    823830            WHERE ".FB_PHOTO_TABLE.".aid = ".FB_ALBUM_TABLE.".aid AND ".FB_ALBUM_TABLE.".hidden = 0
    824831            ORDER BY rand() LIMIT ".$count;
    825   $photos = $wpdb->get_results($query, ARRAY_A); 
     832  $photos = $wpdb->get_results($query, ARRAY_A);
    826833  for($i = 0; $i < count($photos); $i++) {
    827834    $photos[$i]['link'] = fb_get_photo_link($photos[$i]['pid']);
     
    832839function fb_get_recent_photos($count) {
    833840  global $wpdb;
    834   $photos = $wpdb->get_results('SELECT * FROM '.FB_PHOTO_TABLE.' ORDER BY created DESC LIMIT '.$count, ARRAY_A); 
     841  $photos = $wpdb->get_results('SELECT * FROM '.FB_PHOTO_TABLE.' ORDER BY created DESC LIMIT '.$count, ARRAY_A);
    835842  for($i = 0; $i < count($photos); $i++) {
    836843    $photos[$i]['link'] = fb_get_photo_link($photos[$i]);
     
    855862      $page_link .= strstr($page_link, '?') ? '&' : '?';
    856863      $page_link .= 'album_p='.$album_p;
    857       $page_link .= '#photo'.($photo['ordinal']);   
     864      $page_link .= '#photo'.($photo['ordinal']);
    858865      break;
    859866    case 'embedded':
     
    867874function fb_hidden_pages($array = array()) {
    868875  global $wpdb;
    869  
     876
    870877  if(get_option('fb_hide_pages') == 1) {
    871878    $query = 'SELECT page_id FROM '.FB_ALBUM_TABLE;
     
    873880    $query = 'SELECT page_id FROM '.FB_ALBUM_TABLE.' WHERE hidden = 1';
    874881  }
    875      
     882
    876883  $results = $wpdb->get_results($query, ARRAY_A);
    877884  if(!$results) return $array;
    878  
     885
    879886  foreach($results as $result) {
    880887    $array[] = $result['page_id'];
     
    889896function fb_display($content) {
    890897  global $wpdb;
    891  
     898
    892899  // get variables to check if this is part of fotobook
    893900  $post             = $GLOBALS['post'];
     
    895902  $post_parent      = $post->post_parent;
    896903  $albums_page_id   = get_option('fb_albums_page');
    897    
     904
    898905  // don't show password protected pages
    899906  if (!empty($post->post_password) && $_COOKIE['wp-postpass_'. COOKIEHASH] != $post->post_password) {
    900907    return $content;
    901908  }
    902  
     909
    903910  if($post_id != $albums_page_id && $post_parent != $albums_page_id) {
    904911    return $content;
    905912  }
    906  
     913
    907914  // display all albums
    908915  if($post_id == $albums_page_id) {
    909916    return fb_display_main($content);
    910917  }
    911  
     918
    912919  // display individual albums
    913920  if($post_parent == $albums_page_id && $post_parent != 0) {
     
    922929function fb_display_main($content) {
    923930  remove_filter('the_content','wpautop');
    924      
     931
    925932  // buffer the output
    926933  ob_start();
    927    
     934
    928935  // get albums
    929936  $albums = fb_get_album(null, null, true);
    930937  $album_count = sizeof($albums);
    931   if(!$albums) { 
     938  if(!$albums) {
    932939    echo "<p>There are no albums.</p>";
    933940    return;
     
    947954  $last_album = $first_album + $albums_per_page - 1;
    948955  $last_album = $last_album > $album_count ? $album_count : $last_album;
    949  
     956
    950957  // generate pagination
    951958  if($page_count == 1) {
     
    957964    $next_link = $curr_page + 1 <= $page_count ? $curr_page + 1 : false;
    958965    if($next_link)
    959       $next_link = $album_link.(strstr($album_link, '?') ? '&amp;album_p='.($next_link) : '?album_p='.($next_link));       
     966      $next_link = $album_link.(strstr($album_link, '?') ? '&amp;album_p='.($next_link) : '?album_p='.($next_link));
    960967    $pagination = '';
    961968    for($i = 1; $i <= $page_count; $i++) {
    962       if($i == $curr_page) 
     969      if($i == $curr_page)
    963970        $pagination .= '<b>'.$i.'</b>';
    964971      else {
     
    968975    }
    969976  }
    970  
     977
    971978  // now get rid of all albums in the array that aren't displayed on this page
    972979  $albums = array_slice_preserve_keys($albums, $first_album-1, $albums_per_page);
     
    975982    $albums[$key]['thumb'] = fb_get_photo($albums[$key]['cover_pid'], 'thumb');
    976983  }
    977    
     984
    978985  include(FB_STYLE_PATH.'main.php');
    979   ?> 
     986  ?>
    980987  <div id="fotobook-credits" style="text-align: right;">
    981988    <small>Powered by <a href="http://www.aaronharp.com/dev/wp-fotobook/">Fotobook</a></small>
    982   </div>     
     989  </div>
    983990<?php
    984991  // now capture the buffer and add it to $content
     
    992999
    9931000  // buffer the output
    994   // ob_start();
    995  
     1001  ob_start();
     1002
    9961003  $albums_page_link = htmlentities(get_permalink(get_option('fb_albums_page')));
    997   $page_link = get_permalink($page_id); 
     1004  $page_link = get_permalink($page_id);
    9981005  $album_id = fb_get_album_id($page_id);
    9991006  $album = fb_get_album($album_id);
     
    10061013  array_unshift($photos, ''); // moves all the keys down
    10071014  unset($photos[0]);
    1008  
     1015
    10091016  // check if page is hidden
    10101017  if($album['hidden'] == 1) {
     
    10121019    return $message.$content;
    10131020  }
    1014  
     1021
    10151022  // html encode all captions
    10161023  foreach($photos as $key=>$photo) {
    1017     $photos[$key]['caption'] = function_exists('seems_utf8') && seems_utf8($photo['caption']) 
     1024    $photos[$key]['caption'] = function_exists('seems_utf8') && seems_utf8($photo['caption'])
    10181025                               ? htmlentities($photo['caption'], ENT_QUOTES, 'utf-8')
    10191026                               : htmlentities($photo['caption'], ENT_QUOTES);
    10201027  }
    1021  
     1028
    10221029  $thumb_size = get_option('fb_thumb_size');
    10231030  $number_cols = get_option('fb_number_cols');
    10241031  $number_rows = get_option('fb_number_rows') == 0 ? ceil($photo_count / $number_cols) : get_option('fb_number_rows');
    10251032  $photos_per_page = $number_cols * $number_rows;
    1026  
     1033
    10271034  $page_count = ceil($photo_count / $photos_per_page);
    10281035  $curr_page = ($_GET['album_p'] <= $page_count) && ($_GET['album_p'] > 0) ? $_GET['album_p'] : 1;
     
    10311038  $last_photo = $last_photo > $photo_count ? $photo_count : $last_photo;
    10321039  $rows_curr_page = ceil(($last_photo - $first_photo + 1) / $number_cols);
    1033  
     1040
    10341041  // generate pagination
    10351042  if($page_count == 1) {
     
    10411048    $next_link = $curr_page < $page_count ? $curr_page + 1 : null;
    10421049    if($next_link)
    1043       $next_link = $page_link.(strstr($page_link, '?') ? '&amp;album_p='.($next_link) : '?album_p='.($next_link));       
     1050      $next_link = $page_link.(strstr($page_link, '?') ? '&amp;album_p='.($next_link) : '?album_p='.($next_link));
    10441051    $pagination = '';
    10451052    for($i = 1; $i <= $page_count; $i++) {
    1046       if($i == $curr_page) 
     1053      if($i == $curr_page)
    10471054        $pagination .= '<b>'.$i.'</b>';
    10481055      else {
     
    10521059    }
    10531060  }
    1054  
     1061
    10551062  // album info
    10561063  $description = $album['description'];
    10571064  $location = $album['location'];
    1058        
     1065
    10591066  // add hidden links for all images before so that next and previous
    10601067  // buttons in lightbox will display these images as well
     
    10661073    $hidden_bottom .= "<a href=\"{$photos[$i]['src_big']}\" rel=\"lightbox[fotobook]\" title=\"{$photos[$i]['caption']}\"></a>";
    10671074  }
    1068  
     1075
    10691076  // now get rid of all photos in the array that aren't displayed on this page
    10701077  $photos = array_slice_preserve_keys($photos, $first_photo-1, $photos_per_page);
     
    10751082  <?php include(FB_STYLE_PATH.'album.php') ?>
    10761083  <p style="display: none"><?php echo $hidden_bottom ?></p>
    1077 <?php 
    1078   //$content .= ob_get_clean();
     1084<?php
     1085  $content .= ob_get_clean();
    10791086  return $content;
    10801087}
     
    10851092
    10861093  // buffer the output
    1087   ob_start(); 
     1094  ob_start();
    10881095
    10891096  // get photos
     
    10911098  $photo_count = sizeof($photos);
    10921099  array_unshift($photos, ''); // moves all the keys down
    1093   unset($photos[0]); 
    1094  
     1100  unset($photos[0]);
     1101
    10951102  // pagination
    1096   $page_link = get_permalink($page_id); 
     1103  $page_link = get_permalink($page_id);
    10971104  $curr = ($photo <= $photo_count && $photo > 0) ? $photo : 1;
    10981105  $next = ($curr + 1 <= $photo_count) ? $curr + 1 : false;
     
    11031110    $prev_link = $page_link.(strstr($page_link, '?') ? '&amp;photo='.($prev) : '?photo='.($prev));
    11041111  $photo = $photos[$curr];
    1105  
     1112
    11061113  // html encode caption
    1107   $photo['caption'] = function_exists('seems_utf8') && seems_utf8($photo['caption']) 
     1114  $photo['caption'] = function_exists('seems_utf8') && seems_utf8($photo['caption'])
    11081115                      ? htmlentities($photo['caption'], ENT_QUOTES, 'utf-8')
    11091116                      : htmlentities($photo['caption'], ENT_QUOTES);
    1110  
     1117
    11111118  // get max width
    11121119  $width = get_option('fb_embedded_width');
    1113  
     1120
    11141121  include(FB_STYLE_PATH.'photo.php');
    11151122
     
    11311138  <?php if($albums) { ?>
    11321139  <ul id="fb-manage-list">
    1133     <?php 
    1134     for($i = 0; $i < sizeof($albums); $i++): 
     1140    <?php
     1141    for($i = 0; $i < sizeof($albums); $i++):
    11351142    $album = $albums[$i];
    11361143    $thumb = fb_get_photo($album['cover_pid'], 'small');
     
    11521159      <div style="clear: left"></div>
    11531160    </li>
    1154     <?php endfor; ?>   
     1161    <?php endfor; ?>
    11551162  </ul>
    11561163  <script language="javascript">
     
    11591166  <?php } else { ?>
    11601167  <p>There are no albums.</p>
    1161   <?php 
     1168  <?php
    11621169  }
    11631170}
    11641171
    11651172function fb_info_box() {
    1166 ?> 
     1173?>
    11671174  <div id="fb-info">
    11681175    <h3>Info</h3>
     
    11771184      <li><a href="http://www.aaronharp.com/dev/">Need a developer?</a></li>
    11781185    </ul>
    1179    
    1180   </div> 
     1186
     1187  </div>
    11811188<?php
    11821189}
     
    12181225  if(isset($_GET['type']) && $_GET['type'] == 'image')
    12191226    $tabs['fotobook'] = 'Fotobook';
    1220   return $tabs; 
     1227  return $tabs;
    12211228}
    12221229
     
    12421249  </style>
    12431250  <form id="image-form">
    1244   <?php 
    1245   if(isset($_GET['aid'])): 
     1251  <?php
     1252  if(isset($_GET['aid'])):
    12461253  $album = fb_get_album($_GET['aid']);
    12471254  $photos = fb_get_photos($_GET['aid']);
     
    12701277    if(size == 'thumb') var src = fbThumb;
    12711278    else var src = fbFull;
    1272     var html = 
     1279    var html =
    12731280      '<a href="'+fbLink+'" class="fb-photo">' +
    12741281      '<img src="'+src+'" alt="'+fbCaption+'" />' +
     
    12851292  </script>
    12861293  <h3><?php echo $album['name'] ?> <a href="<?php echo $link ?>" style="font-size: 11px">&laquo; Back to Albums</a></small></h2>
    1287  
     1294
    12881295  <div id="fb-insert-popup">
    12891296    Insert...<br />
     
    12921299    <br /><a href="#" onclick="this.parentNode.style.display = 'none'; return false;">[close]</a>
    12931300  </div>
    1294  
     1301
    12951302  <ul id="fb-photos-tab">
    12961303    <?php foreach($photos as $photo): ?>
     
    12991306        <img src="<?php echo $photo['src']; ?>" />
    13001307      </a>
    1301     </li> 
     1308    </li>
    13021309    <?php endforeach; ?>
    13031310  </ul>
    1304   <?php 
    1305   else: 
     1311  <?php
     1312  else:
    13061313  $albums = fb_get_album();
    13071314  ?>
    13081315  <h3>Select an Album</h3>
    13091316  <ul id="fb-manage-list">
    1310     <?php 
    1311     foreach($albums as $album): 
     1317    <?php
     1318    foreach($albums as $album):
    13121319    $thumb = fb_get_photo($album['cover_pid'], 'small');
    13131320    ?>
     
    13341341  add_action('admin_head_media_upload_fotobook_tab', 'media_admin_css');
    13351342} else {
    1336   add_filter('wp_upload_tabs', 'fb_add_upload_tab'); 
     1343  add_filter('wp_upload_tabs', 'fb_add_upload_tab');
    13371344}
    13381345
     
    13531360
    13541361function fb_photos_widget($count = '4', $mode = 'random', $size = '80') {
    1355  
     1362
    13561363  // this is a widget
    13571364  if(is_array($count)) {
    13581365    extract($count);
    1359    
     1366
    13601367    $options = get_option('fb_photos_widget');
    13611368    if(is_array($options)) {
     
    13681375    echo $before_widget . $before_title . $title . $after_title;
    13691376  }
    1370  
     1377
    13711378  if($mode == 'recent') {
    13721379    $photos = fb_get_recent_photos($count);
     
    13741381    $photos = fb_get_random_photos($count);
    13751382  }
    1376    
    1377   // if the thumbnail size is set larger than the size of 
     1383
     1384  // if the thumbnail size is set larger than the size of
    13781385  // the thumbnail, use the full size photo
    13791386  if($size > 130) {
    1380     foreach($photos as $key=>$photo) 
     1387    foreach($photos as $key=>$photo)
    13811388      $photos[$key]['src'] = $photos[$key]['src_big'];
    13821389  }
    1383  
     1390
    13841391  if($photos) {
    13851392    include(FB_PLUGIN_PATH.'styles/photos-widget.php');
     
    13871394    echo '<p>There are no photos.</p>';
    13881395  }
    1389  
     1396
    13901397  echo $after_widget;
    13911398}
     
    14041411  }
    14051412  $options['title'] = htmlspecialchars($options['title'], ENT_QUOTES);
    1406  
     1413
    14071414  ?>
    14081415  <p><label for="fb-title"><?php echo __('Title:'); ?>
     
    14251432function fb_albums_widget($count = '4', $mode = 'recent') {
    14261433  global $wpdb;
    1427  
     1434
    14281435  if(is_array($count)) {
    14291436    extract($count);
     
    14351442      $count = $options['count'];
    14361443    }
    1437  
     1444
    14381445    echo $before_widget . $before_title . $title . $after_title;
    14391446  }
    1440  
     1447
    14411448  if($mode == 'recent') {
    14421449    $albums = $wpdb->get_results('SELECT name, aid, page_id FROM '.FB_ALBUM_TABLE.' WHERE hidden = 0 ORDER BY modified DESC LIMIT '.$count, ARRAY_A);
     
    14441451    $albums = $wpdb->get_results('SELECT name, aid, page_id FROM '.FB_ALBUM_TABLE.' WHERE hidden = 0 ORDER BY rand() LIMIT '.$count, ARRAY_A);
    14451452  }
    1446    
     1453
    14471454  if($albums) {
    14481455    include(FB_PLUGIN_PATH.'styles/albums-widget.php');
     
    14651472  }
    14661473  $options['title'] = htmlspecialchars($options['title'], ENT_QUOTES);
    1467  
     1474
    14681475  ?>
    14691476  <p><label for="fb-title"><?php echo __('Title:'); ?>
     
    15131520  else
    15141521    $endOffset = count($array);
    1515  
     1522
    15161523  // collect elements
    15171524  foreach($array as $key=>$value)
     
    15211528    $i++;
    15221529  }
    1523  
     1530
    15241531  // return
    15251532  return($result);
  • fotobook/trunk/readme.txt

    r167260 r191361  
    44Tags: facebook, photos, images, gallery, fotobook, import, widget, media
    55Requires at least: 2.5
    6 Tested up to: 2.8.4
    7 Stable tag: 3.1.7
     6Tested up to: 2.9.1
     7Stable tag: 3.1.8
    88
    99Fotobook is a WordPress plugin that will link to your Facebook account(s) and import all of your photo albums for use in your WordPress installation. It uses the Facebook's API so importing your photos is a breeze.
     
    7979
    8080== Changelog ==
     81
     82= 3.1.8 =
     83
     84* Fixed a bug where some accounts weren't able to import albums.  Props to Aaron Ibrahim for figuring this one out!
    8185
    8286= 3.1.7 =
Note: See TracChangeset for help on using the changeset viewer.