Changeset 191361
- Timestamp:
- 01/08/2010 02:54:38 AM (16 years ago)
- Location:
- fotobook/trunk
- Files:
-
- 2 edited
-
fotobook.php (modified) (95 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
fotobook/trunk/fotobook.php
r167260 r191361 7 7 Author: Aaron Harp 8 8 Author URI: http://www.aaronharp.com/ 9 Version: 3.1. 79 Version: 3.1.8 10 10 */ 11 11 12 12 /* 13 13 Copyright 2008 Aaron Harp 14 14 15 15 This program is free software: you can redistribute it and/or modify 16 16 it under the terms of the GNU General Public License as published by … … 40 40 define('FB_OPTIONS_URL', 'options-general.php?page=fotobook/options-fotobook.php'); 41 41 define('FB_WEBSITE', 'http://www.aaronharp.com/dev/wp-fotobook/'); 42 define('FB_VERSION', 3.1 7);42 define('FB_VERSION', 3.18); 43 43 define('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¤cy_code=USD&lc=US&bn=PP%2dDonationsBF&charset=UTF%2d8'); 44 44 … … 80 80 var $msg = null; 81 81 var $secret = null; 82 82 83 83 function FacebookAPI() { 84 84 if(version_compare('5', PHP_VERSION, "<=")) { … … 87 87 require_once('facebook-platform/php4client/facebook.php'); 88 88 } 89 89 90 90 $this->facebook = new Facebook(FB_API_KEY, FB_API_SECRET, null, true); 91 91 $this->client = $this->facebook->api_client; 92 92 93 93 global $fb_message; 94 94 $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 97 97 // versions of Fotobook, if so remove it to start over 98 98 $sessions = get_option('fb_facebook_session'); … … 100 100 update_option('fb_facebook_session', ''); 101 101 } 102 102 103 103 if(isset($_POST['activate-facebook'])) { 104 104 $this->get_auth_session($_POST['activate-facebook']); … … 110 110 if(isset($_GET['deactivate-facebook']) && isset($this->sessions[$_GET['deactivate-facebook']])) { 111 111 $this->remove_user($_GET['deactivate-facebook']); 112 } 113 112 } 113 114 114 // get token every time for additional users 115 $this->token = $this->get_auth_token(); 116 115 $this->token = $this->get_auth_token(); 116 117 117 } 118 118 … … 127 127 if(!$this->token) { 128 128 $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.'; 130 130 } 131 131 return $this->token; … … 134 134 function get_sessions() { 135 135 $sessions = get_option('fb_facebook_session'); 136 136 137 137 // make sure all accounts are still active 138 138 if(!$sessions) return false; … … 147 147 unset($sessions[$key]); 148 148 update_option('fb_facebook_session',$sessions); 149 } 150 } 151 149 } 150 } 151 152 152 $this->sessions = $sessions; 153 153 return count($sessions) > 0; … … 163 163 $this->msg = 'Unable to activate account. [Error #'.$this->client->error_code.']'; 164 164 return false; 165 } 166 165 } 166 167 167 // check to see if this account is already linked 168 168 $active = array(); … … 174 174 return false; 175 175 } 176 176 177 177 // get user's name 178 178 $this->client->session_key = $new_session['session_key']; … … 180 180 $user = $this->client->users_getInfo($new_session['uid'], array('name')); 181 181 $new_session['name'] = $user[0]['name']; 182 //if(!$new_session['name']) 182 //if(!$new_session['name']) 183 183 //return false; 184 184 if(!is_array($sessions)) $sessions = array(); … … 188 188 return count($sessions) > 0; 189 189 } 190 190 191 191 function remove_user($key) { 192 192 // remove all of this user's albums and photos 193 193 global $wpdb; 194 194 195 195 $albums = fb_get_album(0, $this->sessions[$key]['uid']); 196 196 if(is_array($albums)) { … … 199 199 } 200 200 } 201 201 202 202 $wpdb->query('DELETE FROM '.FB_ALBUM_TABLE.' WHERE owner = '.$this->sessions[$key]['uid']); 203 203 $wpdb->query('DELETE FROM '.FB_PHOTO_TABLE.' WHERE owner = '.$this->sessions[$key]['uid']); 204 204 205 205 $this->msg = 'The link to '.$this->sessions[$key]['name'].'\'s Facebook account has been removed.'; 206 206 207 207 unset($this->sessions[$key]); 208 update_option('fb_facebook_session', $this->sessions); 209 } 210 208 update_option('fb_facebook_session', $this->sessions); 209 } 210 211 211 function update_progress($increment) { 212 212 if($increment == -1) { 213 213 $progress = 0; 214 214 } else { 215 $progress = get_option('fb_update_progress') + $increment; 215 $progress = get_option('fb_update_progress') + $increment; 216 216 } 217 217 if($progress > 100) … … 220 220 return $progress; 221 221 } 222 222 223 223 function update_albums() { 224 224 global $wpdb; 225 225 226 226 // allow the script plenty of time to make requests 227 227 if(!ini_get('safe_mode') && !strstr(ini_get('disabled_functions'), 'set_time_limit')) 228 228 set_time_limit(500); 229 229 230 230 // reset album import progress 231 231 update_option('fb_update_progress', 0); 232 232 233 233 // 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 236 236 // determine how much to increment the progress bar after each request 237 237 $incr = 100 / (count($this->sessions) * 3); 238 238 239 239 // get albums for each user from Facebook 240 240 $fb_albums = array(); $fb_photos = array(); … … 244 244 $this->client->session_key = $session['session_key']; 245 245 $this->client->secret = $session['secret']; 246 246 247 247 // get all albums 248 248 $result = $this->client->photos_getAlbums($uid, null); 249 249 if(!is_array($result)) // if the current user has no photos so move on 250 250 continue; 251 $fb_albums = array_merge($fb_albums, $result); 251 $fb_albums = array_merge($fb_albums, $result); 252 252 $this->update_progress($incr); 253 253 254 254 // get all photos 255 255 $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)")); 256 256 $this->update_progress($incr); 257 257 258 258 // get photos of user 259 259 $fb_user_photos = $this->client->photos_get($uid, null, null); … … 262 262 $fb_photos = array_merge($fb_photos, (array)$fb_user_photos); 263 263 $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", 273 273 'size'=>count($fb_user_photos) 274 274 ); 275 275 } 276 276 277 277 if(!$fb_albums || $this->client->error_code) { 278 278 $this->msg = 'Fotobook encountered an error while retrieving your photos. [Error #'.$this->client->error_code.']'; 279 279 return false; 280 280 } 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 285 285 $albums = fb_get_album(); 286 286 if($albums) { … … 288 288 $wp_albums[$album['aid']] = $album; 289 289 } 290 } 291 290 } 291 292 292 // go through all the facebook albums see which ones need to be added 293 293 foreach($fb_albums as $album) { 294 294 $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 297 297 if($wp_album) { 298 298 $hidden = $wp_album['hidden']; … … 302 302 if($album['name'] != $wp_album['name']) { 303 303 fb_update_page($page_id, $album['name']); 304 } 304 } 305 305 } else { 306 $page_id = fb_add_page($album['name']); 306 $page_id = fb_add_page($album['name']); 307 307 } 308 308 } else { … … 311 311 $ordinal = fb_get_next_ordinal(); 312 312 } 313 313 314 314 // 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 317 317 // add album to database 318 318 if(!get_magic_quotes_runtime()) { 319 319 $album['name'] = addslashes($album['name']); 320 320 $album['description'] = addslashes($album['description']); 321 $album['location'] = addslashes($album['location']); 321 $album['location'] = addslashes($album['location']); 322 322 } 323 323 $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 328 328 // update the photos 329 329 $wpdb->query('DELETE FROM '.FB_PHOTO_TABLE); … … 339 339 FB_PHOTO_TABLE, $photo['pid'], $photo['aid'], $photo['owner'], $photo['src'], $photo['src_big'], $photo['src_small'], $photo['link'], $photo['caption'], $photo['created'], $ordinal); 340 340 $wpdb->query($photo_query); 341 341 342 342 // handle ordinal 343 343 $last_aid = $photo['aid']; 344 344 $ordinal++; 345 345 } 346 346 347 347 // put IDs of all albums in an array 348 348 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(); 353 353 if(count($wp_albums) > 0) { 354 354 // delete albums that have been removed off of Facebook … … 356 356 if(!@in_array($album['aid'], $album_ids)) { 357 357 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']."'"); 359 359 } 360 360 } 361 361 362 362 // delete superfluous pages 363 363 foreach($wp_albums as $album) { … … 368 368 if(!in_array($page['ID'], $album_pages)) { 369 369 fb_delete_page($page['ID']); 370 } 371 } 372 } 373 370 } 371 } 372 } 373 374 374 // now reset the order if needed 375 375 if($reset_order) { 376 376 fb_reset_album_order(); 377 377 } 378 378 379 379 if(!$this->msg) { 380 $this->msg = 'Albums imported successfully.'; 380 $this->msg = 'Albums imported successfully.'; 381 381 } 382 382 $this->update_progress(-1); 383 383 } 384 } 384 } 385 385 386 386 //---------------------// … … 390 390 function fb_initialize() { 391 391 global $wpdb; 392 392 393 393 // add default options 394 394 add_option('fb_albums_page', 0); … … 401 401 add_option('fb_embedded_width', 0); 402 402 add_option('fb_hide_pages', 0); 403 403 404 404 $photo_table_query = "CREATE TABLE ".FB_PHOTO_TABLE." ( 405 405 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 '', 408 408 owner bigint(20) NOT NULL default 0, 409 409 src varchar(255) NOT NULL default '', … … 418 418 419 419 $album_table_query = "CREATE TABLE ".FB_ALBUM_TABLE." ( 420 aid bigint(20) unsigned NOT NULL,420 aid varchar(25) NOT NULL default '', 421 421 page_id int(11) NOT NULL, 422 cover_pid bigint(20) NOT NULL,422 cover_pid varchar(25) NOT NULL default '', 423 423 owner int(11) NOT NULL, 424 424 name varchar(255) NOT NULL default '', … … 432 432 ordinal tinyint(4) NOT NULL default 0, 433 433 UNIQUE KEY id (aid) 434 ) TYPE = MyISAM"; 435 436 fb_upgrade_tables(); 437 434 ) TYPE = MyISAM"; 435 436 fb_upgrade_tables(); 437 438 438 if(!fb_table_exists(FB_PHOTO_TABLE)) { 439 439 $wpdb->query($photo_table_query); 440 440 } 441 441 442 442 if(!fb_table_exists(FB_ALBUM_TABLE)) { 443 443 $wpdb->query($album_table_query); 444 444 } 445 445 446 446 update_option('fb_version', FB_VERSION); 447 447 } … … 466 466 function fb_upgrade_tables() { 467 467 global $wpdb; 468 468 469 469 // this is an upgrade from v1 470 470 if(fb_table_exists(FB_ALBUM_TABLE) && $wpdb->get_results('SHOW COLUMNS FROM '.FB_ALBUM_TABLE." WHERE Field = 'timecached'")) { 471 471 $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 475 475 // this is an upgrade to fix the duplicate key issue 476 476 if(fb_table_exists(FB_PHOTO_TABLE) && !$wpdb->get_results('SHOW COLUMNS FROM '.FB_PHOTO_TABLE." WHERE Field = 'id'")) { … … 480 480 if(get_option('fb_version') < 3.17) 481 481 $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 } 482 489 } 483 490 … … 503 510 'post_type' => 'page', 504 511 'post_content' => '', 505 'post_title' => $name, 512 'post_title' => $name, 506 513 'post_status' => 'publish', 507 514 'post_parent' => get_option('fb_albums_page'), … … 514 521 function fb_delete_page($id) { 515 522 if(fb_page_exists($id)) { 516 523 517 524 // disable conflicting Wordbook action 518 525 remove_action('delete_post', 'wordbook_delete_post'); 519 526 520 527 wp_delete_post($id); 521 528 } … … 524 531 function fb_update_page($id, $name, $hidden = false) { 525 532 global $wpdb; 526 533 527 534 $parent = get_option('fb_albums_page'); 528 535 $comment_status = get_option('fb_album_cmts') ? 'open' : 'closed'; … … 538 545 ); 539 546 540 if(get_bloginfo('version') >= 2.1) { 547 if(get_bloginfo('version') >= 2.1) { 541 548 $array['post_status'] = 'publish'; 542 549 $array['post_type'] = 'page'; … … 544 551 $array['post_status'] = 'static'; 545 552 } 546 553 547 554 return wp_update_post($array); 548 555 } … … 567 574 echo 'success'; 568 575 } 569 576 570 577 // handle order change 571 578 elseif(isset($_POST['order'])) { … … 573 580 echo 'success'; 574 581 } 575 582 576 583 // handle order reset 577 584 elseif(isset($_POST['reset_order'])) { … … 579 586 echo 'The albums have been ordered by their modification date.'; 580 587 } 581 588 582 589 // handle remove all 583 590 elseif(isset($_POST['remove_all'])) { … … 585 592 echo 'All albums have been removed.'; 586 593 } 587 594 588 595 // handle update progress request 589 596 elseif(isset($_POST['progress'])) { 590 597 echo round(get_option('fb_update_progress')); 591 598 } 592 599 593 600 // handle update albums request 594 601 elseif(isset($_POST['update'])) { … … 601 608 } 602 609 } 603 610 604 611 // handle albums list request 605 612 elseif(isset($_POST['albums_list'])) { 606 613 fb_display_manage_list($_POST['message']); 607 614 } 608 615 609 616 exit; 610 617 } … … 612 619 function fb_options_update_albums_page($new_id) { 613 620 global $wpdb; 614 621 615 622 $old_id = get_option('fb_albums_page'); 616 623 if($old_id == $new_id) { 617 624 return true; 618 625 } 619 626 620 627 $albums = fb_get_album(); 621 628 if(sizeof($albums) > 0) { … … 624 631 } 625 632 } 626 627 update_option('fb_albums_page', $new_id); 633 634 update_option('fb_albums_page', $new_id); 628 635 } 629 636 630 637 function fb_options_toggle_comments($status = true) { 631 638 global $wpdb; 632 639 633 640 if($status) $status = 'open'; 634 641 else $status = 'closed'; 635 642 636 643 $fb_albums_page = get_option('fb_albums_page'); 637 644 638 645 $wpdb->query("UPDATE ".FB_POSTS_TABLE." SET comment_status='$status' WHERE post_parent = $fb_albums_page"); 639 646 } … … 650 657 if ($handle = opendir(FB_PLUGIN_PATH.'styles')) { 651 658 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)) 653 660 $styles[] = $file; 654 661 } … … 661 668 function fb_parent_dropdown( $default = 0, $parent = 0, $level = 0 ) { 662 669 global $wpdb; 663 670 664 671 $albums_page = get_option('fb_albums_page'); 665 672 666 673 $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" ); 667 674 … … 708 715 $query = 'SELECT * FROM '.FB_ALBUM_TABLE.' '; 709 716 $where = ''; 710 717 711 718 if($album_id || $user_id || $displayed_only) 712 719 $query .= "WHERE "; 713 720 714 721 if($album_id) { 715 $query .= "aid = $album_id";722 $query .= "aid = '$album_id' "; 716 723 $array = $wpdb->get_results($query, ARRAY_A); 717 724 return $array[0]; … … 725 732 $where .= "hidden = 0 "; 726 733 } 727 734 728 735 $query .= $where."ORDER BY ordinal DESC"; 729 736 730 737 $results = $wpdb->get_results($query, ARRAY_A); 731 738 732 739 return $results; 733 740 } … … 742 749 $order = array_reverse(explode(',', $order)); 743 750 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"); 745 752 } 746 753 } … … 752 759 return false; 753 760 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']."'"); 755 762 } 756 763 return true; … … 779 786 function fb_toggle_album_hiding($id) { 780 787 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'"); 782 789 $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'"); 784 791 return true; 785 792 } … … 789 796 790 797 $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"; 793 800 $photos = $wpdb->get_results($query, ARRAY_A); 794 801 … … 799 806 global $wpdb; 800 807 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'"; 802 809 $photo = $wpdb->get_row($query, ARRAY_A); 803 810 switch ($size) { … … 820 827 global $wpdb; 821 828 $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." 823 830 WHERE ".FB_PHOTO_TABLE.".aid = ".FB_ALBUM_TABLE.".aid AND ".FB_ALBUM_TABLE.".hidden = 0 824 831 ORDER BY rand() LIMIT ".$count; 825 $photos = $wpdb->get_results($query, ARRAY_A); 832 $photos = $wpdb->get_results($query, ARRAY_A); 826 833 for($i = 0; $i < count($photos); $i++) { 827 834 $photos[$i]['link'] = fb_get_photo_link($photos[$i]['pid']); … … 832 839 function fb_get_recent_photos($count) { 833 840 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); 835 842 for($i = 0; $i < count($photos); $i++) { 836 843 $photos[$i]['link'] = fb_get_photo_link($photos[$i]); … … 855 862 $page_link .= strstr($page_link, '?') ? '&' : '?'; 856 863 $page_link .= 'album_p='.$album_p; 857 $page_link .= '#photo'.($photo['ordinal']); 864 $page_link .= '#photo'.($photo['ordinal']); 858 865 break; 859 866 case 'embedded': … … 867 874 function fb_hidden_pages($array = array()) { 868 875 global $wpdb; 869 876 870 877 if(get_option('fb_hide_pages') == 1) { 871 878 $query = 'SELECT page_id FROM '.FB_ALBUM_TABLE; … … 873 880 $query = 'SELECT page_id FROM '.FB_ALBUM_TABLE.' WHERE hidden = 1'; 874 881 } 875 882 876 883 $results = $wpdb->get_results($query, ARRAY_A); 877 884 if(!$results) return $array; 878 885 879 886 foreach($results as $result) { 880 887 $array[] = $result['page_id']; … … 889 896 function fb_display($content) { 890 897 global $wpdb; 891 898 892 899 // get variables to check if this is part of fotobook 893 900 $post = $GLOBALS['post']; … … 895 902 $post_parent = $post->post_parent; 896 903 $albums_page_id = get_option('fb_albums_page'); 897 904 898 905 // don't show password protected pages 899 906 if (!empty($post->post_password) && $_COOKIE['wp-postpass_'. COOKIEHASH] != $post->post_password) { 900 907 return $content; 901 908 } 902 909 903 910 if($post_id != $albums_page_id && $post_parent != $albums_page_id) { 904 911 return $content; 905 912 } 906 913 907 914 // display all albums 908 915 if($post_id == $albums_page_id) { 909 916 return fb_display_main($content); 910 917 } 911 918 912 919 // display individual albums 913 920 if($post_parent == $albums_page_id && $post_parent != 0) { … … 922 929 function fb_display_main($content) { 923 930 remove_filter('the_content','wpautop'); 924 931 925 932 // buffer the output 926 933 ob_start(); 927 934 928 935 // get albums 929 936 $albums = fb_get_album(null, null, true); 930 937 $album_count = sizeof($albums); 931 if(!$albums) { 938 if(!$albums) { 932 939 echo "<p>There are no albums.</p>"; 933 940 return; … … 947 954 $last_album = $first_album + $albums_per_page - 1; 948 955 $last_album = $last_album > $album_count ? $album_count : $last_album; 949 956 950 957 // generate pagination 951 958 if($page_count == 1) { … … 957 964 $next_link = $curr_page + 1 <= $page_count ? $curr_page + 1 : false; 958 965 if($next_link) 959 $next_link = $album_link.(strstr($album_link, '?') ? '&album_p='.($next_link) : '?album_p='.($next_link)); 966 $next_link = $album_link.(strstr($album_link, '?') ? '&album_p='.($next_link) : '?album_p='.($next_link)); 960 967 $pagination = ''; 961 968 for($i = 1; $i <= $page_count; $i++) { 962 if($i == $curr_page) 969 if($i == $curr_page) 963 970 $pagination .= '<b>'.$i.'</b>'; 964 971 else { … … 968 975 } 969 976 } 970 977 971 978 // now get rid of all albums in the array that aren't displayed on this page 972 979 $albums = array_slice_preserve_keys($albums, $first_album-1, $albums_per_page); … … 975 982 $albums[$key]['thumb'] = fb_get_photo($albums[$key]['cover_pid'], 'thumb'); 976 983 } 977 984 978 985 include(FB_STYLE_PATH.'main.php'); 979 ?> 986 ?> 980 987 <div id="fotobook-credits" style="text-align: right;"> 981 988 <small>Powered by <a href="http://www.aaronharp.com/dev/wp-fotobook/">Fotobook</a></small> 982 </div> 989 </div> 983 990 <?php 984 991 // now capture the buffer and add it to $content … … 992 999 993 1000 // buffer the output 994 //ob_start();995 1001 ob_start(); 1002 996 1003 $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); 998 1005 $album_id = fb_get_album_id($page_id); 999 1006 $album = fb_get_album($album_id); … … 1006 1013 array_unshift($photos, ''); // moves all the keys down 1007 1014 unset($photos[0]); 1008 1015 1009 1016 // check if page is hidden 1010 1017 if($album['hidden'] == 1) { … … 1012 1019 return $message.$content; 1013 1020 } 1014 1021 1015 1022 // html encode all captions 1016 1023 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']) 1018 1025 ? htmlentities($photo['caption'], ENT_QUOTES, 'utf-8') 1019 1026 : htmlentities($photo['caption'], ENT_QUOTES); 1020 1027 } 1021 1028 1022 1029 $thumb_size = get_option('fb_thumb_size'); 1023 1030 $number_cols = get_option('fb_number_cols'); 1024 1031 $number_rows = get_option('fb_number_rows') == 0 ? ceil($photo_count / $number_cols) : get_option('fb_number_rows'); 1025 1032 $photos_per_page = $number_cols * $number_rows; 1026 1033 1027 1034 $page_count = ceil($photo_count / $photos_per_page); 1028 1035 $curr_page = ($_GET['album_p'] <= $page_count) && ($_GET['album_p'] > 0) ? $_GET['album_p'] : 1; … … 1031 1038 $last_photo = $last_photo > $photo_count ? $photo_count : $last_photo; 1032 1039 $rows_curr_page = ceil(($last_photo - $first_photo + 1) / $number_cols); 1033 1040 1034 1041 // generate pagination 1035 1042 if($page_count == 1) { … … 1041 1048 $next_link = $curr_page < $page_count ? $curr_page + 1 : null; 1042 1049 if($next_link) 1043 $next_link = $page_link.(strstr($page_link, '?') ? '&album_p='.($next_link) : '?album_p='.($next_link)); 1050 $next_link = $page_link.(strstr($page_link, '?') ? '&album_p='.($next_link) : '?album_p='.($next_link)); 1044 1051 $pagination = ''; 1045 1052 for($i = 1; $i <= $page_count; $i++) { 1046 if($i == $curr_page) 1053 if($i == $curr_page) 1047 1054 $pagination .= '<b>'.$i.'</b>'; 1048 1055 else { … … 1052 1059 } 1053 1060 } 1054 1061 1055 1062 // album info 1056 1063 $description = $album['description']; 1057 1064 $location = $album['location']; 1058 1065 1059 1066 // add hidden links for all images before so that next and previous 1060 1067 // buttons in lightbox will display these images as well … … 1066 1073 $hidden_bottom .= "<a href=\"{$photos[$i]['src_big']}\" rel=\"lightbox[fotobook]\" title=\"{$photos[$i]['caption']}\"></a>"; 1067 1074 } 1068 1075 1069 1076 // now get rid of all photos in the array that aren't displayed on this page 1070 1077 $photos = array_slice_preserve_keys($photos, $first_photo-1, $photos_per_page); … … 1075 1082 <?php include(FB_STYLE_PATH.'album.php') ?> 1076 1083 <p style="display: none"><?php echo $hidden_bottom ?></p> 1077 <?php 1078 //$content .= ob_get_clean();1084 <?php 1085 $content .= ob_get_clean(); 1079 1086 return $content; 1080 1087 } … … 1085 1092 1086 1093 // buffer the output 1087 ob_start(); 1094 ob_start(); 1088 1095 1089 1096 // get photos … … 1091 1098 $photo_count = sizeof($photos); 1092 1099 array_unshift($photos, ''); // moves all the keys down 1093 unset($photos[0]); 1094 1100 unset($photos[0]); 1101 1095 1102 // pagination 1096 $page_link = get_permalink($page_id); 1103 $page_link = get_permalink($page_id); 1097 1104 $curr = ($photo <= $photo_count && $photo > 0) ? $photo : 1; 1098 1105 $next = ($curr + 1 <= $photo_count) ? $curr + 1 : false; … … 1103 1110 $prev_link = $page_link.(strstr($page_link, '?') ? '&photo='.($prev) : '?photo='.($prev)); 1104 1111 $photo = $photos[$curr]; 1105 1112 1106 1113 // 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']) 1108 1115 ? htmlentities($photo['caption'], ENT_QUOTES, 'utf-8') 1109 1116 : htmlentities($photo['caption'], ENT_QUOTES); 1110 1117 1111 1118 // get max width 1112 1119 $width = get_option('fb_embedded_width'); 1113 1120 1114 1121 include(FB_STYLE_PATH.'photo.php'); 1115 1122 … … 1131 1138 <?php if($albums) { ?> 1132 1139 <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++): 1135 1142 $album = $albums[$i]; 1136 1143 $thumb = fb_get_photo($album['cover_pid'], 'small'); … … 1152 1159 <div style="clear: left"></div> 1153 1160 </li> 1154 <?php endfor; ?> 1161 <?php endfor; ?> 1155 1162 </ul> 1156 1163 <script language="javascript"> … … 1159 1166 <?php } else { ?> 1160 1167 <p>There are no albums.</p> 1161 <?php 1168 <?php 1162 1169 } 1163 1170 } 1164 1171 1165 1172 function fb_info_box() { 1166 ?> 1173 ?> 1167 1174 <div id="fb-info"> 1168 1175 <h3>Info</h3> … … 1177 1184 <li><a href="http://www.aaronharp.com/dev/">Need a developer?</a></li> 1178 1185 </ul> 1179 1180 </div> 1186 1187 </div> 1181 1188 <?php 1182 1189 } … … 1218 1225 if(isset($_GET['type']) && $_GET['type'] == 'image') 1219 1226 $tabs['fotobook'] = 'Fotobook'; 1220 return $tabs; 1227 return $tabs; 1221 1228 } 1222 1229 … … 1242 1249 </style> 1243 1250 <form id="image-form"> 1244 <?php 1245 if(isset($_GET['aid'])): 1251 <?php 1252 if(isset($_GET['aid'])): 1246 1253 $album = fb_get_album($_GET['aid']); 1247 1254 $photos = fb_get_photos($_GET['aid']); … … 1270 1277 if(size == 'thumb') var src = fbThumb; 1271 1278 else var src = fbFull; 1272 var html = 1279 var html = 1273 1280 '<a href="'+fbLink+'" class="fb-photo">' + 1274 1281 '<img src="'+src+'" alt="'+fbCaption+'" />' + … … 1285 1292 </script> 1286 1293 <h3><?php echo $album['name'] ?> <a href="<?php echo $link ?>" style="font-size: 11px">« Back to Albums</a></small></h2> 1287 1294 1288 1295 <div id="fb-insert-popup"> 1289 1296 Insert...<br /> … … 1292 1299 <br /><a href="#" onclick="this.parentNode.style.display = 'none'; return false;">[close]</a> 1293 1300 </div> 1294 1301 1295 1302 <ul id="fb-photos-tab"> 1296 1303 <?php foreach($photos as $photo): ?> … … 1299 1306 <img src="<?php echo $photo['src']; ?>" /> 1300 1307 </a> 1301 </li> 1308 </li> 1302 1309 <?php endforeach; ?> 1303 1310 </ul> 1304 <?php 1305 else: 1311 <?php 1312 else: 1306 1313 $albums = fb_get_album(); 1307 1314 ?> 1308 1315 <h3>Select an Album</h3> 1309 1316 <ul id="fb-manage-list"> 1310 <?php 1311 foreach($albums as $album): 1317 <?php 1318 foreach($albums as $album): 1312 1319 $thumb = fb_get_photo($album['cover_pid'], 'small'); 1313 1320 ?> … … 1334 1341 add_action('admin_head_media_upload_fotobook_tab', 'media_admin_css'); 1335 1342 } else { 1336 add_filter('wp_upload_tabs', 'fb_add_upload_tab'); 1343 add_filter('wp_upload_tabs', 'fb_add_upload_tab'); 1337 1344 } 1338 1345 … … 1353 1360 1354 1361 function fb_photos_widget($count = '4', $mode = 'random', $size = '80') { 1355 1362 1356 1363 // this is a widget 1357 1364 if(is_array($count)) { 1358 1365 extract($count); 1359 1366 1360 1367 $options = get_option('fb_photos_widget'); 1361 1368 if(is_array($options)) { … … 1368 1375 echo $before_widget . $before_title . $title . $after_title; 1369 1376 } 1370 1377 1371 1378 if($mode == 'recent') { 1372 1379 $photos = fb_get_recent_photos($count); … … 1374 1381 $photos = fb_get_random_photos($count); 1375 1382 } 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 1378 1385 // the thumbnail, use the full size photo 1379 1386 if($size > 130) { 1380 foreach($photos as $key=>$photo) 1387 foreach($photos as $key=>$photo) 1381 1388 $photos[$key]['src'] = $photos[$key]['src_big']; 1382 1389 } 1383 1390 1384 1391 if($photos) { 1385 1392 include(FB_PLUGIN_PATH.'styles/photos-widget.php'); … … 1387 1394 echo '<p>There are no photos.</p>'; 1388 1395 } 1389 1396 1390 1397 echo $after_widget; 1391 1398 } … … 1404 1411 } 1405 1412 $options['title'] = htmlspecialchars($options['title'], ENT_QUOTES); 1406 1413 1407 1414 ?> 1408 1415 <p><label for="fb-title"><?php echo __('Title:'); ?> … … 1425 1432 function fb_albums_widget($count = '4', $mode = 'recent') { 1426 1433 global $wpdb; 1427 1434 1428 1435 if(is_array($count)) { 1429 1436 extract($count); … … 1435 1442 $count = $options['count']; 1436 1443 } 1437 1444 1438 1445 echo $before_widget . $before_title . $title . $after_title; 1439 1446 } 1440 1447 1441 1448 if($mode == 'recent') { 1442 1449 $albums = $wpdb->get_results('SELECT name, aid, page_id FROM '.FB_ALBUM_TABLE.' WHERE hidden = 0 ORDER BY modified DESC LIMIT '.$count, ARRAY_A); … … 1444 1451 $albums = $wpdb->get_results('SELECT name, aid, page_id FROM '.FB_ALBUM_TABLE.' WHERE hidden = 0 ORDER BY rand() LIMIT '.$count, ARRAY_A); 1445 1452 } 1446 1453 1447 1454 if($albums) { 1448 1455 include(FB_PLUGIN_PATH.'styles/albums-widget.php'); … … 1465 1472 } 1466 1473 $options['title'] = htmlspecialchars($options['title'], ENT_QUOTES); 1467 1474 1468 1475 ?> 1469 1476 <p><label for="fb-title"><?php echo __('Title:'); ?> … … 1513 1520 else 1514 1521 $endOffset = count($array); 1515 1522 1516 1523 // collect elements 1517 1524 foreach($array as $key=>$value) … … 1521 1528 $i++; 1522 1529 } 1523 1530 1524 1531 // return 1525 1532 return($result); -
fotobook/trunk/readme.txt
r167260 r191361 4 4 Tags: facebook, photos, images, gallery, fotobook, import, widget, media 5 5 Requires at least: 2.5 6 Tested up to: 2. 8.47 Stable tag: 3.1. 76 Tested up to: 2.9.1 7 Stable tag: 3.1.8 8 8 9 9 Fotobook 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. … … 79 79 80 80 == 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! 81 85 82 86 = 3.1.7 =
Note: See TracChangeset
for help on using the changeset viewer.