Changeset 167816
- Timestamp:
- 10/27/2009 09:41:36 PM (16 years ago)
- Location:
- fotobook/trunk
- Files:
-
- 5 edited
-
cron.php (modified) (1 diff)
-
fotobook.php (modified) (14 diffs)
-
js/admin.js (modified) (2 diffs)
-
manage-fotobook.php (modified) (2 diffs)
-
options-fotobook.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
fotobook/trunk/cron.php
r167260 r167816 6 6 // handle cron request 7 7 if(isset($_GET['update']) && isset($_GET['secret']) && $_GET['secret'] == get_option('fb_secret')) { 8 echo 'Updating Fotobook (be patient)...';9 ob_flush(); flush();10 $facebook = new FacebookAPI;11 if($facebook->link_active())12 $facebook->update_albums();13 echo 'Done';8 echo 'Updating Fotobook (be patient)...'; 9 ob_flush(); flush(); 10 $facebook = new FacebookAPI; 11 if($facebook->link_active()) 12 $facebook->update_albums(); 13 echo 'Done'; 14 14 } else { 15 echo 'Invalid URL';15 echo 'Invalid URL'; 16 16 } 17 17 -
fotobook/trunk/fotobook.php
r167815 r167816 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 … … 20 20 This program is distributed in the hope that it will be useful, 21 21 but WITHOUT ANY WARRANTY; without even the implied warranty of 22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 23 GNU General Public License for more details. 24 24 25 25 You should have received a copy of the GNU General Public License 26 along with this program. If not, see <http://www.gnu.org/licenses/>.26 along with this program. If not, see <http://www.gnu.org/licenses/>. 27 27 */ 28 28 … … 34 34 define('FB_POSTS_TABLE', $table_prefix.'posts'); 35 35 define('FB_PLUGIN_PATH', ABSPATH.'/wp-content/plugins/fotobook/'); 36 define('FB_PLUGIN_URL', get_option('siteurl').'/wp-content/plugins/fotobook/');37 define('FB_STYLE_URL', FB_PLUGIN_URL.'styles/'.get_option('fb_style').'/');38 define('FB_STYLE_PATH', FB_PLUGIN_PATH.'styles/'.get_option('fb_style').'/');39 define('FB_MANAGE_URL', (get_bloginfo('version') >= 2.7 ? 'media-new.php' : 'edit.php') .'?page=fotobook/manage-fotobook.php');36 define('FB_PLUGIN_URL', get_option('siteurl').'/wp-content/plugins/fotobook/'); 37 define('FB_STYLE_URL', FB_PLUGIN_URL.'styles/'.get_option('fb_style').'/'); 38 define('FB_STYLE_PATH', FB_PLUGIN_PATH.'styles/'.get_option('fb_style').'/'); 39 define('FB_MANAGE_URL', (get_bloginfo('version') >= 2.7 ? 'media-new.php' : 'edit.php') .'?page=fotobook/manage-fotobook.php'); 40 40 define('FB_OPTIONS_URL', 'options-general.php?page=fotobook/options-fotobook.php'); 41 define('FB_WEBSITE', 'http://www.aaronharp.com/dev/wp-fotobook/');42 define('FB_VERSION', 3.17);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');41 define('FB_WEBSITE', 'http://www.aaronharp.com/dev/wp-fotobook/'); 42 define('FB_VERSION', 3.17); 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 45 45 // facebook configuration variables 46 define('FB_API_SERVER', 'http://api.facebook.com');46 define('FB_API_SERVER', 'http://api.facebook.com'); 47 47 define('FB_LOGIN_SERVER', 'http://www.facebook.com'); 48 define('FB_REST_SERVER', FB_API_SERVER.'/restserver.php');49 define('FB_API_KEY', '759543efe161e1085f7f6c97791e1eab');50 define('FB_API_SECRET', '639a774490d803ce22cf8b7277403914');48 define('FB_REST_SERVER', FB_API_SERVER.'/restserver.php'); 49 define('FB_API_KEY', '759543efe161e1085f7f6c97791e1eab'); 50 define('FB_API_SECRET', '639a774490d803ce22cf8b7277403914'); 51 51 52 52 // upgrade if needed 53 53 if(fb_needs_upgrade()) { 54 fb_initialize();54 fb_initialize(); 55 55 } 56 56 … … 58 58 59 59 function fb_admin_scripts() { 60 wp_enqueue_script('jquery');61 wp_enqueue_script('prototype');62 wp_enqueue_script('scriptaculous-effects');63 wp_enqueue_script('scriptaculous-dragdrop');64 wp_enqueue_script('progressbar', FB_PLUGIN_URL.'js/progress.js', array('prototype'), '0.1');65 wp_enqueue_script('fotobook-js', FB_PLUGIN_URL.'js/admin.js', array('prototype'), FB_VERSION);66 add_thickbox();60 wp_enqueue_script('jquery'); 61 wp_enqueue_script('prototype'); 62 wp_enqueue_script('scriptaculous-effects'); 63 wp_enqueue_script('scriptaculous-dragdrop'); 64 wp_enqueue_script('progressbar', FB_PLUGIN_URL.'js/progress.js', array('prototype'), '0.1'); 65 wp_enqueue_script('fotobook-js', FB_PLUGIN_URL.'js/admin.js', array('prototype'), FB_VERSION); 66 add_thickbox(); 67 67 } 68 68 add_action('load-fotobook/manage-fotobook.php', 'fb_admin_scripts'); … … 75 75 76 76 class FacebookAPI { 77 var $facebook = null;78 var $client= null;79 var $sessions = null;80 var $token= null;81 var $error= false;82 var $msg= null;83 var $secret= null;84 85 function FacebookAPI() {86 include_once('facebook-platform/facebook.php');87 88 $this->facebook= new Facebook(FB_API_KEY, FB_API_SECRET, null, true);89 $this->client = $this->facebook->api_client;90 91 global $fb_message;92 $this->msg = &$fb_message;93 94 // check if the facebook session is the structure from older95 // versions of Fotobook, if so remove it to start over96 $sessions = get_option('fb_facebook_session');97 if(isset($sessions['session_key'])) {98 update_option('fb_facebook_session', '');99 }100 101 // get sessions102 $this->get_sessions();103 104 // get token every time for additional users105 $this->token = $this->get_auth_token();106 107 }108 109 function link_active() {110 return count($this->sessions) > 0;111 }112 113 function get_auth_token() {114 $this->client->session_key = '';115 $this->client->secret = FB_API_SECRET;116 $this->token = $this->client->auth_createToken();117 if(!$this->token) {118 $this->error = true;119 $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.';120 }121 return $this->token;122 }123 124 function get_sessions() {125 $sessions = get_option('fb_facebook_session');126 127 // make sure all accounts are still active128 if(!$sessions) return false;129 foreach($sessions as $key=>$value) {130 $this->client->session_key = $sessions[$key]['session_key'];131 $this->client->secret = $sessions[$key]['secret'];132 $user = $this->client->users_getInfo($sessions[$key]['uid'], array('name'));133 if($this->client->error_code == 102) {134 // if it can't get the user than remove it from the Facebook session array because135 // the link isn't active anymore136 $this->msg = 'The link to '.$sessions[$key]['name'].'\'s account was lost for some reason.Please add it again.';137 unset($sessions[$key]);138 update_option('fb_facebook_session',$sessions);139 } 140 }141 142 $this->sessions = $sessions;143 return count($sessions) > 0;144 }145 146 function get_auth_session($token) {147 $this->get_sessions();148 $sessions = $this->sessions;149 150 try {151 $new_session = $this->client->auth_getSession($token);152 } catch( Exception $e ) {153 $this->error = true;154 $this->msg = 'Unable to activate account.';155 return false;156 }157 158 // check to see if this account is already linked159 $active = array();160 if(is_array($sessions)) {161 foreach($sessions as $value) { $active[] = $value['uid']; }162 }163 if(in_array($new_session['uid'], $active)) {164 $this->msg = 'That user is already linked to Fotobook.';165 return false;166 }167 168 // get user's name169 $this->client->session_key = $new_session['session_key'];170 $this->client->secret = $new_session['secret'];171 $user = $this->client->users_getInfo($new_session['uid'], array('name'));172 $new_session['name'] = $user[0]['name'];173 //if(!$new_session['name'])174 //return false;175 if(!is_array($sessions)) $sessions = array();176 $sessions[] = $new_session;177 update_option('fb_facebook_session', $sessions);178 $this->msg = 'Fotobook is now linked to '.$new_session['name'].'\'s Facebook account.Now you need to <a href="'.FB_MANAGE_URL.'">import</a> your albums.';179 180 $this->get_sessions();181 return count($sessions) > 0;182 }183 184 function remove_user($key) {185 // remove all of this user's albums and photos186 global $wpdb;187 188 $albums = fb_get_album(0, $this->sessions[$key]['uid']);189 if(is_array($albums)) {190 foreach($albums as $album) {191 fb_delete_page($album['page_id']);192 }193 }194 195 $wpdb->query('DELETE FROM '.FB_ALBUM_TABLE.' WHERE owner = '.$this->sessions[$key]['uid']);196 $wpdb->query('DELETE FROM '.FB_PHOTO_TABLE.' WHERE owner = '.$this->sessions[$key]['uid']);197 198 $this->msg = 'The link to '.$this->sessions[$key]['name'].'\'s Facebook account has been removed.';199 200 unset($this->sessions[$key]);201 update_option('fb_facebook_session', $this->sessions); 202 }203 204 function update_progress($increment) {205 if($increment == -1) {206 $progress = 0;207 } else {208 $progress = get_option('fb_update_progress') + $increment; 209 }210 if($progress > 100)211 $progress = 100;212 update_option('fb_update_progress', $progress);213 return $progress;214 }215 216 function update_albums() {217 global $wpdb;218 219 // allow the script plenty of time to make requests220 if(!ini_get('safe_mode') && !strstr(ini_get('disabled_functions'), 'set_time_limit'))221 set_time_limit(500);222 223 // reset album import progress224 update_option('fb_update_progress', 0);225 226 // if this is the first import then reset the order at the end to make the newest on top227 $reset_order = count(fb_get_album()) > 0 ? false : true; 228 229 // determine how much to increment the progress bar after each request230 $incr = 100 / (count($this->sessions) * 3);231 232 // get albums for each user from Facebook233 $fb_albums = array(); $fb_photos = array();234 foreach($this->sessions as $key=>$session) {235 // setup general info236 $uid = $session['uid'];237 $this->client->session_key = $session['session_key'];238 $this->client->secret = $session['secret'];239 240 // get all albums241 $result = $this->client->photos_getAlbums($uid, null);242 if(!is_array($result)) // if the current user has no photos so move on243 continue;244 $fb_albums = array_merge($fb_albums, $result);245 $this->update_progress($incr);246 247 // get all photos248 $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)"));249 $this->update_progress($incr);250 251 // get photos of user252 $fb_user_photos = $this->client->photos_get($uid, null, null);253 if($fb_user_photos) {254 foreach($fb_user_photos as $k=>$v) $fb_user_photos[$k]['aid'] = $uid;255 $fb_photos = array_merge($fb_photos, (array)$fb_user_photos);256 $fb_albums[] = array(257 'aid'=>$uid,258 'cover_pid'=>$fb_user_photos[0]['pid'],259 'owner'=>$uid,260 'name'=>'Photos of '.(count($this->sessions) > 1 ? $session['name'] : 'Me'),261 'created'=>time(),262 'modified'=>time(),263 'description'=>'',264 'location'=>'',265 'link'=>"http://www.facebook.com/photo_search.php?id=$uid",266 'size'=>count($fb_user_photos)267 );268 }269 270 if(!$fb_albums || $this->client->error_code) {271 $this->msg= 'Fotobook encountered an error while retrieving your photos. [Error #'.$this->client->error_code.']';272 return false;273 }274 275 }276 277 // put all the albums in an array with the aid as the key 278 $albums = fb_get_album();279 if($albums) {280 foreach($albums as $album) {281 $wp_albums[$album['aid']] = $album;282 }283 } 284 285 // go through all the facebook albums see which ones need to be added286 foreach($fb_albums as $album) {287 $wp_album = isset($wp_albums[$album['aid']]) ? $wp_albums[$album['aid']] : false;288 289 // create or update the WP page 290 if($wp_album) {291 $hidden= $wp_album['hidden'];292 $page_id = $wp_album['page_id'];293 $ordinal = $wp_album['ordinal'];294 if(fb_page_exists($page_id)) {295 if($album['name'] != $wp_album['name']) {296 fb_update_page($page_id, $album['name']);297 }298 } else {299 $page_id = fb_add_page($album['name']);300 }301 } else {302 $page_id = fb_add_page($album['name']);303 $hidden = 0;304 $ordinal = fb_get_next_ordinal();305 }306 307 // if updating, remove from database first308 $wpdb->query('DELETE FROM '.FB_ALBUM_TABLE.' WHERE aid = '.$album['aid']);309 310 // add album to database311 if(!get_magic_quotes_runtime()) {312 $album['name'] = addslashes($album['name']);313 $album['description'] = addslashes($album['description']);314 $album['location'] = addslashes($album['location']); 315 }316 317 $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'",318 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); 319 $wpdb->query($album_query); 320 }321 322 // update the photos323 $wpdb->query('DELETE FROM '.FB_PHOTO_TABLE);324 $ordinal = 1;325 foreach($fb_photos as $photo) {326 if($last_aid != $photo['aid']) { // reset ordinal if we're on a new album now327 $ordinal = 1;328 }329 if(!get_magic_quotes_runtime()) {330 $photo['caption'] = addslashes($photo['caption']);331 }332 $photo_query = sprintf("INSERT INTO %s SET pid='%s', aid='%s', owner='%s', src='%s', src_big='%s', src_small='%s', link='%s', caption='%s', created=FROM_UNIXTIME(%s), ordinal='%s'",333 FB_PHOTO_TABLE, $photo['pid'], $photo['aid'], $photo['owner'], $photo['src'], $photo['src_big'], $photo['src_small'], $photo['link'], $photo['caption'], $photo['created'], $ordinal);334 $wpdb->query($photo_query);335 336 // handle ordinal337 $last_aid = $photo['aid'];338 $ordinal++;339 }340 341 // put IDs of all albums in an array342 foreach($fb_albums as $album) {343 $album_ids[] = $album['aid']; 344 }345 346 $wp_albums = fb_get_album(); 347 if(count($wp_albums) > 0) {348 // delete albums that have been removed off of Facebook349 foreach($wp_albums as $album) {350 if(!@in_array($album['aid'], $album_ids)) {351 fb_delete_page($album['page_id']);352 $wpdb->query('DELETE FROM '.FB_ALBUM_TABLE.' WHERE aid = '.$album['aid']);353 }354 }355 356 // delete superfluous pages357 foreach($wp_albums as $album) {358 $album_pages[] = $album['page_id'];359 }360 $wp_pages = $wpdb->get_results('SELECT ID FROM '.FB_POSTS_TABLE.' WHERE post_parent = '.get_option('fb_albums_page'), ARRAY_A);361 foreach($wp_pages as $page) {362 if(!in_array($page['ID'], $album_pages)) {363 fb_delete_page($page['ID']);364 }365 } 366 }367 368 // now reset the order if needed369 if($reset_order) {370 fb_reset_album_order();371 }372 373 if(!$this->msg) {374 $this->msg = 'Albums imported successfully.'; 375 }376 $this->update_progress(-1);377 }77 var $facebook = null; 78 var $client = null; 79 var $sessions = null; 80 var $token = null; 81 var $error = false; 82 var $msg = null; 83 var $secret = null; 84 85 function FacebookAPI() { 86 include_once('facebook-platform/facebook.php'); 87 88 $this->facebook = new Facebook(FB_API_KEY, FB_API_SECRET, null, true); 89 $this->client = $this->facebook->api_client; 90 91 global $fb_message; 92 $this->msg = &$fb_message; 93 94 // check if the facebook session is the structure from older 95 // versions of Fotobook, if so remove it to start over 96 $sessions = get_option('fb_facebook_session'); 97 if(isset($sessions['session_key'])) { 98 update_option('fb_facebook_session', ''); 99 } 100 101 // get sessions 102 $this->get_sessions(); 103 104 // get token every time for additional users 105 $this->token = $this->get_auth_token(); 106 107 } 108 109 function link_active() { 110 return count($this->sessions) > 0; 111 } 112 113 function get_auth_token() { 114 $this->client->session_key = ''; 115 $this->client->secret = FB_API_SECRET; 116 $this->token = $this->client->auth_createToken(); 117 if(!$this->token) { 118 $this->error = true; 119 $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.'; 120 } 121 return $this->token; 122 } 123 124 function get_sessions() { 125 $sessions = get_option('fb_facebook_session'); 126 127 // make sure all accounts are still active 128 if(!$sessions) return false; 129 foreach($sessions as $key=>$value) { 130 $this->client->session_key = $sessions[$key]['session_key']; 131 $this->client->secret = $sessions[$key]['secret']; 132 $user = $this->client->users_getInfo($sessions[$key]['uid'], array('name')); 133 if($this->client->error_code == 102) { 134 // if it can't get the user than remove it from the Facebook session array because 135 // the link isn't active anymore 136 $this->msg = 'The link to '.$sessions[$key]['name'].'\'s account was lost for some reason. Please add it again.'; 137 unset($sessions[$key]); 138 update_option('fb_facebook_session',$sessions); 139 } 140 } 141 142 $this->sessions = $sessions; 143 return count($sessions) > 0; 144 } 145 146 function get_auth_session($token) { 147 $this->get_sessions(); 148 $sessions = $this->sessions; 149 150 try { 151 $new_session = $this->client->auth_getSession($token); 152 } catch( Exception $e ) { 153 $this->error = true; 154 $this->msg = 'Unable to activate account.'; 155 return false; 156 } 157 158 // check to see if this account is already linked 159 $active = array(); 160 if(is_array($sessions)) { 161 foreach($sessions as $value) { $active[] = $value['uid']; } 162 } 163 if(in_array($new_session['uid'], $active)) { 164 $this->msg = 'That user is already linked to Fotobook.'; 165 return false; 166 } 167 168 // get user's name 169 $this->client->session_key = $new_session['session_key']; 170 $this->client->secret = $new_session['secret']; 171 $user = $this->client->users_getInfo($new_session['uid'], array('name')); 172 $new_session['name'] = $user[0]['name']; 173 //if(!$new_session['name']) 174 //return false; 175 if(!is_array($sessions)) $sessions = array(); 176 $sessions[] = $new_session; 177 update_option('fb_facebook_session', $sessions); 178 $this->msg = 'Fotobook is now linked to '.$new_session['name'].'\'s Facebook account. Now you need to <a href="'.FB_MANAGE_URL.'">import</a> your albums.'; 179 180 $this->get_sessions(); 181 return count($sessions) > 0; 182 } 183 184 function remove_user($key) { 185 // remove all of this user's albums and photos 186 global $wpdb; 187 188 $albums = fb_get_album(0, $this->sessions[$key]['uid']); 189 if(is_array($albums)) { 190 foreach($albums as $album) { 191 fb_delete_page($album['page_id']); 192 } 193 } 194 195 $wpdb->query('DELETE FROM '.FB_ALBUM_TABLE.' WHERE owner = '.$this->sessions[$key]['uid']); 196 $wpdb->query('DELETE FROM '.FB_PHOTO_TABLE.' WHERE owner = '.$this->sessions[$key]['uid']); 197 198 $this->msg = 'The link to '.$this->sessions[$key]['name'].'\'s Facebook account has been removed.'; 199 200 unset($this->sessions[$key]); 201 update_option('fb_facebook_session', $this->sessions); 202 } 203 204 function update_progress($increment) { 205 if($increment == -1) { 206 $progress = 0; 207 } else { 208 $progress = get_option('fb_update_progress') + $increment; 209 } 210 if($progress > 100) 211 $progress = 100; 212 update_option('fb_update_progress', $progress); 213 return $progress; 214 } 215 216 function update_albums() { 217 global $wpdb; 218 219 // allow the script plenty of time to make requests 220 if(!ini_get('safe_mode') && !strstr(ini_get('disabled_functions'), 'set_time_limit')) 221 set_time_limit(500); 222 223 // reset album import progress 224 update_option('fb_update_progress', 0); 225 226 // if this is the first import then reset the order at the end to make the newest on top 227 $reset_order = count(fb_get_album()) > 0 ? false : true; 228 229 // determine how much to increment the progress bar after each request 230 $incr = 100 / (count($this->sessions) * 3); 231 232 // get albums for each user from Facebook 233 $fb_albums = array(); $fb_photos = array(); 234 foreach($this->sessions as $key=>$session) { 235 // setup general info 236 $uid = $session['uid']; 237 $this->client->session_key = $session['session_key']; 238 $this->client->secret = $session['secret']; 239 240 // get all albums 241 $result = $this->client->photos_getAlbums($uid, null); 242 if(!is_array($result)) // if the current user has no photos so move on 243 continue; 244 $fb_albums = array_merge($fb_albums, $result); 245 $this->update_progress($incr); 246 247 // get all photos 248 $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)")); 249 $this->update_progress($incr); 250 251 // get photos of user 252 $fb_user_photos = $this->client->photos_get($uid, null, null); 253 if($fb_user_photos) { 254 foreach($fb_user_photos as $k=>$v) $fb_user_photos[$k]['aid'] = $uid; 255 $fb_photos = array_merge($fb_photos, (array)$fb_user_photos); 256 $fb_albums[] = array( 257 'aid'=>$uid, 258 'cover_pid'=>$fb_user_photos[0]['pid'], 259 'owner'=>$uid, 260 'name'=>'Photos of '.(count($this->sessions) > 1 ? $session['name'] : 'Me'), 261 'created'=>time(), 262 'modified'=>time(), 263 'description'=>'', 264 'location'=>'', 265 'link'=>"http://www.facebook.com/photo_search.php?id=$uid", 266 'size'=>count($fb_user_photos) 267 ); 268 } 269 270 if(!$fb_albums || $this->client->error_code) { 271 $this->msg = 'Fotobook encountered an error while retrieving your photos. [Error #'.$this->client->error_code.']'; 272 return false; 273 } 274 275 } 276 277 // put all the albums in an array with the aid as the key 278 $albums = fb_get_album(); 279 if($albums) { 280 foreach($albums as $album) { 281 $wp_albums[$album['aid']] = $album; 282 } 283 } 284 285 // go through all the facebook albums see which ones need to be added 286 foreach($fb_albums as $album) { 287 $wp_album = isset($wp_albums[$album['aid']]) ? $wp_albums[$album['aid']] : false; 288 289 // create or update the WP page 290 if($wp_album) { 291 $hidden = $wp_album['hidden']; 292 $page_id = $wp_album['page_id']; 293 $ordinal = $wp_album['ordinal']; 294 if(fb_page_exists($page_id)) { 295 if($album['name'] != $wp_album['name']) { 296 fb_update_page($page_id, $album['name']); 297 } 298 } else { 299 $page_id = fb_add_page($album['name']); 300 } 301 } else { 302 $page_id = fb_add_page($album['name']); 303 $hidden = 0; 304 $ordinal = fb_get_next_ordinal(); 305 } 306 307 // if updating, remove from database first 308 $wpdb->query('DELETE FROM '.FB_ALBUM_TABLE.' WHERE aid = '.$album['aid']); 309 310 // add album to database 311 if(!get_magic_quotes_runtime()) { 312 $album['name'] = addslashes($album['name']); 313 $album['description'] = addslashes($album['description']); 314 $album['location'] = addslashes($album['location']); 315 } 316 317 $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'", 318 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); 319 $wpdb->query($album_query); 320 } 321 322 // update the photos 323 $wpdb->query('DELETE FROM '.FB_PHOTO_TABLE); 324 $ordinal = 1; 325 foreach($fb_photos as $photo) { 326 if($last_aid != $photo['aid']) { // reset ordinal if we're on a new album now 327 $ordinal = 1; 328 } 329 if(!get_magic_quotes_runtime()) { 330 $photo['caption'] = addslashes($photo['caption']); 331 } 332 $photo_query = sprintf("INSERT INTO %s SET pid='%s', aid='%s', owner='%s', src='%s', src_big='%s', src_small='%s', link='%s', caption='%s', created=FROM_UNIXTIME(%s), ordinal='%s'", 333 FB_PHOTO_TABLE, $photo['pid'], $photo['aid'], $photo['owner'], $photo['src'], $photo['src_big'], $photo['src_small'], $photo['link'], $photo['caption'], $photo['created'], $ordinal); 334 $wpdb->query($photo_query); 335 336 // handle ordinal 337 $last_aid = $photo['aid']; 338 $ordinal++; 339 } 340 341 // put IDs of all albums in an array 342 foreach($fb_albums as $album) { 343 $album_ids[] = $album['aid']; 344 } 345 346 $wp_albums = fb_get_album(); 347 if(count($wp_albums) > 0) { 348 // delete albums that have been removed off of Facebook 349 foreach($wp_albums as $album) { 350 if(!@in_array($album['aid'], $album_ids)) { 351 fb_delete_page($album['page_id']); 352 $wpdb->query('DELETE FROM '.FB_ALBUM_TABLE.' WHERE aid = '.$album['aid']); 353 } 354 } 355 356 // delete superfluous pages 357 foreach($wp_albums as $album) { 358 $album_pages[] = $album['page_id']; 359 } 360 $wp_pages = $wpdb->get_results('SELECT ID FROM '.FB_POSTS_TABLE.' WHERE post_parent = '.get_option('fb_albums_page'), ARRAY_A); 361 foreach($wp_pages as $page) { 362 if(!in_array($page['ID'], $album_pages)) { 363 fb_delete_page($page['ID']); 364 } 365 } 366 } 367 368 // now reset the order if needed 369 if($reset_order) { 370 fb_reset_album_order(); 371 } 372 373 if(!$this->msg) { 374 $this->msg = 'Albums imported successfully.'; 375 } 376 $this->update_progress(-1); 377 } 378 378 } 379 379 … … 383 383 384 384 function fb_initialize() { 385 global $wpdb;386 387 // add default options388 add_option('fb_albums_page', 0);389 add_option('fb_number_rows', 5);390 add_option('fb_number_cols', 3);391 add_option('fb_album_cmts', 1);392 add_option('fb_thumb_size', 130);393 add_option('fb_albums_per_page', 0);394 add_option('fb_style','lightbox');395 add_option('fb_embedded_width', 0);396 add_option('fb_hide_pages', 0);397 398 $photo_table_query = "CREATE TABLE ".FB_PHOTO_TABLE." (399 id bigint(20) unsigned NOT NULL AUTO_INCREMENT,400 pid bigint(20) unsigned NOT NULL,401 aid bigint(20) unsigned NOT NULL default 0,402 owner bigint(20) NOT NULL default 0,403 src varchar(255) NOT NULL default '',404 src_big varchar(255) NOT NULL default '',405 src_small varchar(255) NOT NULL default '',406 link varchar(255) NOT NULL default '',407 caption text NOT NULL,408 created datetime NOT NULL default '0000-00-00 00:00:00',409 ordinal tinyint(4) NOT NULL default 0,410 PRIMARY KEY id (id)411 ) TYPE = MyISAM";412 413 $album_table_query = "CREATE TABLE ".FB_ALBUM_TABLE." (414 aid bigint(20) unsigned NOT NULL,415 page_id int(11) NOT NULL,416 cover_pid bigint(20) NOT NULL,417 owner int(11) NOT NULL,418 name varchar(255) NOT NULL default '',419 description text NOT NULL,420 location varchar(255) NOT NULL default '',421 link varchar(255) NOT NULL,422 size int(11) NOT NULL default 0,423 created datetime NOT NULL default '0000-00-00 00:00:00',424 modified datetime NOT NULL default '0000-00-00 00:00:00',425 hidden tinyint(4) NOT NULL default 0,426 ordinal tinyint(4) NOT NULL default 0,427 UNIQUE KEY id (aid)428 ) TYPE = MyISAM"; 429 430 fb_upgrade_tables(); 431 432 if(!fb_table_exists(FB_PHOTO_TABLE)) {433 $wpdb->query($photo_table_query);434 }435 436 if(!fb_table_exists(FB_ALBUM_TABLE)) {437 $wpdb->query($album_table_query);438 }439 440 update_option('fb_version', FB_VERSION);385 global $wpdb; 386 387 // add default options 388 add_option('fb_albums_page', 0); 389 add_option('fb_number_rows', 5); 390 add_option('fb_number_cols', 3); 391 add_option('fb_album_cmts', 1); 392 add_option('fb_thumb_size', 130); 393 add_option('fb_albums_per_page', 0); 394 add_option('fb_style','lightbox'); 395 add_option('fb_embedded_width', 0); 396 add_option('fb_hide_pages', 0); 397 398 $photo_table_query = "CREATE TABLE ".FB_PHOTO_TABLE." ( 399 id bigint(20) unsigned NOT NULL AUTO_INCREMENT, 400 pid bigint(20) unsigned NOT NULL, 401 aid bigint(20) unsigned NOT NULL default 0, 402 owner bigint(20) NOT NULL default 0, 403 src varchar(255) NOT NULL default '', 404 src_big varchar(255) NOT NULL default '', 405 src_small varchar(255) NOT NULL default '', 406 link varchar(255) NOT NULL default '', 407 caption text NOT NULL, 408 created datetime NOT NULL default '0000-00-00 00:00:00', 409 ordinal tinyint(4) NOT NULL default 0, 410 PRIMARY KEY id (id) 411 ) TYPE = MyISAM"; 412 413 $album_table_query = "CREATE TABLE ".FB_ALBUM_TABLE." ( 414 aid bigint(20) unsigned NOT NULL, 415 page_id int(11) NOT NULL, 416 cover_pid bigint(20) NOT NULL, 417 owner int(11) NOT NULL, 418 name varchar(255) NOT NULL default '', 419 description text NOT NULL, 420 location varchar(255) NOT NULL default '', 421 link varchar(255) NOT NULL, 422 size int(11) NOT NULL default 0, 423 created datetime NOT NULL default '0000-00-00 00:00:00', 424 modified datetime NOT NULL default '0000-00-00 00:00:00', 425 hidden tinyint(4) NOT NULL default 0, 426 ordinal tinyint(4) NOT NULL default 0, 427 UNIQUE KEY id (aid) 428 ) TYPE = MyISAM"; 429 430 fb_upgrade_tables(); 431 432 if(!fb_table_exists(FB_PHOTO_TABLE)) { 433 $wpdb->query($photo_table_query); 434 } 435 436 if(!fb_table_exists(FB_ALBUM_TABLE)) { 437 $wpdb->query($album_table_query); 438 } 439 440 update_option('fb_version', FB_VERSION); 441 441 } 442 442 443 443 function fb_table_exists($table_name) { 444 global $wpdb;445 foreach ($wpdb->get_col("SHOW TABLES",0) as $table ) {446 if ($table == $table_name) return true;447 }448 return false;444 global $wpdb; 445 foreach ($wpdb->get_col("SHOW TABLES",0) as $table ) { 446 if ($table == $table_name) return true; 447 } 448 return false; 449 449 } 450 450 451 451 function fb_needs_upgrade() { 452 $upgrade = get_option('fb_version') != FB_VERSION ? true : false;453 if($upgrade)454 $tables = fb_table_exists(FB_ALBUM_TABLE);455 else456 $tables = false;457 return ($upgrade && $tables);452 $upgrade = get_option('fb_version') != FB_VERSION ? true : false; 453 if($upgrade) 454 $tables = fb_table_exists(FB_ALBUM_TABLE); 455 else 456 $tables = false; 457 return ($upgrade && $tables); 458 458 } 459 459 460 460 function fb_upgrade_tables() { 461 global $wpdb;462 463 // this is an upgrade from v1464 if(fb_table_exists(FB_ALBUM_TABLE) && $wpdb->get_results('SHOW COLUMNS FROM '.FB_ALBUM_TABLE." WHERE Field = 'timecached'")) {465 $wpdb->query('DROP TABLE '.FB_ALBUM_TABLE);466 $wpdb->query('DROP TABLE '.FB_PHOTO_TABLE);467 }468 469 // this is an upgrade to fix the duplicate key issue470 if(fb_table_exists(FB_PHOTO_TABLE) && !$wpdb->get_results('SHOW COLUMNS FROM '.FB_PHOTO_TABLE." WHERE Field = 'id'")) {471 $wpdb->query('ALTER TABLE '.FB_PHOTO_TABLE.' DROP INDEX id, ADD COLUMN id BIGINT(20) AUTO_INCREMENT NOT NULL FIRST, ADD PRIMARY KEY(id)');472 }473 474 // allow captions to contain more than 255 characters475 if(get_option('fb_version') <= 3.2)476 $wpdb->query('ALTER TABLE '.FB_PHOTO_TABLE.' CHANGE `caption` `caption` TEXT');461 global $wpdb; 462 463 // this is an upgrade from v1 464 if(fb_table_exists(FB_ALBUM_TABLE) && $wpdb->get_results('SHOW COLUMNS FROM '.FB_ALBUM_TABLE." WHERE Field = 'timecached'")) { 465 $wpdb->query('DROP TABLE '.FB_ALBUM_TABLE); 466 $wpdb->query('DROP TABLE '.FB_PHOTO_TABLE); 467 } 468 469 // this is an upgrade to fix the duplicate key issue 470 if(fb_table_exists(FB_PHOTO_TABLE) && !$wpdb->get_results('SHOW COLUMNS FROM '.FB_PHOTO_TABLE." WHERE Field = 'id'")) { 471 $wpdb->query('ALTER TABLE '.FB_PHOTO_TABLE.' DROP INDEX id, ADD COLUMN id BIGINT(20) AUTO_INCREMENT NOT NULL FIRST, ADD PRIMARY KEY(id)'); 472 } 473 474 // allow captions to contain more than 255 characters 475 if(get_option('fb_version') <= 3.2) 476 $wpdb->query('ALTER TABLE '.FB_PHOTO_TABLE.' CHANGE `caption` `caption` TEXT'); 477 477 } 478 478 479 479 function fb_add_pages() { 480 if(get_bloginfo('version') >= 2.7)481 add_media_page('Media › Fotobook', 'Fotobook', 8, 'fotobook/manage-fotobook.php');482 else483 add_management_page('Manage › Fotobook', 'Fotobook', 8, 'fotobook/manage-fotobook.php');484 add_options_page('Settings › Fotobook', 'Fotobook', 8, 'fotobook/options-fotobook.php');480 if(get_bloginfo('version') >= 2.7) 481 add_media_page('Media › Fotobook', 'Fotobook', 8, 'fotobook/manage-fotobook.php'); 482 else 483 add_management_page('Manage › Fotobook', 'Fotobook', 8, 'fotobook/manage-fotobook.php'); 484 add_options_page('Settings › Fotobook', 'Fotobook', 8, 'fotobook/options-fotobook.php'); 485 485 } 486 486 … … 490 490 491 491 function fb_add_page($name) { 492 // disable conflicting Wordbook actions493 remove_action('publish_page', 'wordbook_publish');494 remove_action('publish_post', 'wordbook_publish');495 remove_action('transition_post_status', 'wordbook_transition_post_status');496 497 $post = array(498 'post_type'=> 'page',499 'post_content'=> '',500 'post_title'=> $name,501 'post_status'=> 'publish',502 'post_parent'=> get_option('fb_albums_page'),503 'comment_status' => get_option('fb_album_cmts') ? 'open' : 'closed'504 );505 506 return wp_insert_post($post);492 // disable conflicting Wordbook actions 493 remove_action('publish_page', 'wordbook_publish'); 494 remove_action('publish_post', 'wordbook_publish'); 495 remove_action('transition_post_status', 'wordbook_transition_post_status'); 496 497 $post = array( 498 'post_type' => 'page', 499 'post_content' => '', 500 'post_title' => $name, 501 'post_status' => 'publish', 502 'post_parent' => get_option('fb_albums_page'), 503 'comment_status' => get_option('fb_album_cmts') ? 'open' : 'closed' 504 ); 505 506 return wp_insert_post($post); 507 507 } 508 508 509 509 function fb_delete_page($id) { 510 if(fb_page_exists($id)) {511 512 // disable conflicting Wordbook action513 remove_action('delete_post', 'wordbook_delete_post');514 515 wp_delete_post($id);516 }510 if(fb_page_exists($id)) { 511 512 // disable conflicting Wordbook action 513 remove_action('delete_post', 'wordbook_delete_post'); 514 515 wp_delete_post($id); 516 } 517 517 } 518 518 519 519 function fb_update_page($id, $name, $hidden = false) { 520 global $wpdb;521 522 $parent = get_option('fb_albums_page');523 $comment_status = get_option('fb_album_cmts') ? 'open' : 'closed';524 525 $array = array(526 'post_author'=> 1,527 'post_category'=> 0,528 'comment_status' => $comment_status,529 'post_parent'=> $parent,530 'ID'=> $id,531 'post_title'=> addslashes($name),532 'post_name'=> sanitize_title($name)533 );534 535 if(get_bloginfo('version') >= 2.1) { 536 $array['post_status'] = 'publish';537 $array['post_type']= 'page';538 } else {539 $array['post_status'] = 'static';540 }541 542 return wp_update_post($array);520 global $wpdb; 521 522 $parent = get_option('fb_albums_page'); 523 $comment_status = get_option('fb_album_cmts') ? 'open' : 'closed'; 524 525 $array = array( 526 'post_author' => 1, 527 'post_category' => 0, 528 'comment_status' => $comment_status, 529 'post_parent' => $parent, 530 'ID' => $id, 531 'post_title' => addslashes($name), 532 'post_name' => sanitize_title($name) 533 ); 534 535 if(get_bloginfo('version') >= 2.1) { 536 $array['post_status'] = 'publish'; 537 $array['post_type'] = 'page'; 538 } else { 539 $array['post_status'] = 'static'; 540 } 541 542 return wp_update_post($array); 543 543 } 544 544 545 545 function fb_page_exists($id) { 546 global $wpdb;547 $page_row = $wpdb->get_row('SELECT * FROM '.FB_POSTS_TABLE.' WHERE ID = '.$id);548 return $page_row ? true : false;546 global $wpdb; 547 $page_row = $wpdb->get_row('SELECT * FROM '.FB_POSTS_TABLE.' WHERE ID = '.$id); 548 return $page_row ? true : false; 549 549 } 550 550 … … 554 554 555 555 function fb_ajax_handler() { 556 if(!isset($_POST['action']) || $_POST['action'] != 'fotobook')557 return false;558 559 // handle hide/unhide requests560 if(isset($_POST['hide'])) {561 fb_toggle_album_hiding($_POST['hide']);562 echo 'success';563 }564 565 // handle order change566 elseif(isset($_POST['order'])) {567 fb_update_album_order($_POST['order']);568 echo 'success';569 }570 571 // handle order reset572 elseif(isset($_POST['reset_order'])) {573 fb_reset_album_order();574 echo 'The albums have been ordered by their modification date.';575 }576 577 // handle remove all578 elseif(isset($_POST['remove_all'])) {579 fb_remove_all();580 echo 'All albums have been removed.';581 }582 583 // handle update progress request584 elseif(isset($_POST['progress'])) {585 echo round(get_option('fb_update_progress'));586 }587 588 // handle update albums request589 elseif(isset($_POST['update'])) {590 $facebook = new FacebookAPI;591 if($facebook->link_active()) {592 $facebook->update_albums();593 echo $facebook->msg;594 } else {595 echo 'There are no accounts linked to Fotobook.';596 }597 }598 599 // handle albums list request600 elseif(isset($_POST['albums_list'])) {601 fb_display_manage_list($_POST['message']);602 }603 604 exit;556 if(!isset($_POST['action']) || $_POST['action'] != 'fotobook') 557 return false; 558 559 // handle hide/unhide requests 560 if(isset($_POST['hide'])) { 561 fb_toggle_album_hiding($_POST['hide']); 562 echo 'success'; 563 } 564 565 // handle order change 566 elseif(isset($_POST['order'])) { 567 fb_update_album_order($_POST['order']); 568 echo 'success'; 569 } 570 571 // handle order reset 572 elseif(isset($_POST['reset_order'])) { 573 fb_reset_album_order(); 574 echo 'The albums have been ordered by their modification date.'; 575 } 576 577 // handle remove all 578 elseif(isset($_POST['remove_all'])) { 579 fb_remove_all(); 580 echo 'All albums have been removed.'; 581 } 582 583 // handle update progress request 584 elseif(isset($_POST['progress'])) { 585 echo round(get_option('fb_update_progress')); 586 } 587 588 // handle update albums request 589 elseif(isset($_POST['update'])) { 590 $facebook = new FacebookAPI; 591 if($facebook->link_active()) { 592 $facebook->update_albums(); 593 echo $facebook->msg; 594 } else { 595 echo 'There are no accounts linked to Fotobook.'; 596 } 597 } 598 599 // handle albums list request 600 elseif(isset($_POST['albums_list'])) { 601 fb_display_manage_list($_POST['message']); 602 } 603 604 exit; 605 605 } 606 606 607 607 function fb_options_update_albums_page($new_id) { 608 global $wpdb;609 610 $old_id = get_option('fb_albums_page');611 if($old_id == $new_id) {612 return true;613 }614 615 $albums = fb_get_album();616 if(sizeof($albums) > 0) {617 foreach($albums as $album) {618 $wpdb->query("UPDATE ".FB_POSTS_TABLE." SET post_parent = $new_id WHERE ID = ".$album['page_id']);619 }620 }621 622 update_option('fb_albums_page', $new_id); 608 global $wpdb; 609 610 $old_id = get_option('fb_albums_page'); 611 if($old_id == $new_id) { 612 return true; 613 } 614 615 $albums = fb_get_album(); 616 if(sizeof($albums) > 0) { 617 foreach($albums as $album) { 618 $wpdb->query("UPDATE ".FB_POSTS_TABLE." SET post_parent = $new_id WHERE ID = ".$album['page_id']); 619 } 620 } 621 622 update_option('fb_albums_page', $new_id); 623 623 } 624 624 625 625 function fb_options_toggle_comments($status = true) { 626 global $wpdb;627 628 if($status) $status = 'open';629 else $status = 'closed';630 631 $fb_albums_page = get_option('fb_albums_page');632 633 $wpdb->query("UPDATE ".FB_POSTS_TABLE." SET comment_status='$status' WHERE post_parent = $fb_albums_page");626 global $wpdb; 627 628 if($status) $status = 'open'; 629 else $status = 'closed'; 630 631 $fb_albums_page = get_option('fb_albums_page'); 632 633 $wpdb->query("UPDATE ".FB_POSTS_TABLE." SET comment_status='$status' WHERE post_parent = $fb_albums_page"); 634 634 } 635 635 636 636 function fb_albums_page_is_set() { 637 global $wpdb;638 $album_page = get_option('fb_albums_page');639 return $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE ID = '$album_page'") ? true : false;637 global $wpdb; 638 $album_page = get_option('fb_albums_page'); 639 return $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE ID = '$album_page'") ? true : false; 640 640 } 641 641 642 642 function fb_get_styles() { 643 // get styles644 $styles = array();645 if ($handle = opendir(FB_PLUGIN_PATH.'styles')) {646 while (false !== ($file = readdir($handle))) {647 if(substr($file, 0, 1) != '.' && is_dir(FB_PLUGIN_PATH.'styles/'.$file))648 $styles[] = $file;649 }650 closedir($handle);651 }652 sort($styles);653 return $styles;643 // get styles 644 $styles = array(); 645 if ($handle = opendir(FB_PLUGIN_PATH.'styles')) { 646 while (false !== ($file = readdir($handle))) { 647 if(substr($file, 0, 1) != '.' && is_dir(FB_PLUGIN_PATH.'styles/'.$file)) 648 $styles[] = $file; 649 } 650 closedir($handle); 651 } 652 sort($styles); 653 return $styles; 654 654 } 655 655 656 656 function fb_parent_dropdown( $default = 0, $parent = 0, $level = 0 ) { 657 global $wpdb;658 659 $albums_page = get_option('fb_albums_page');660 661 $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" );662 663 if ( $items ) {664 foreach ( $items as $item ) {665 $pad = str_repeat( ' ', $level * 3 );666 if ( $item->ID == $default)667 $current = ' selected="selected"';668 else669 $current = '';670 671 echo "\n\t<option value='$item->ID'$current>$pad " . wp_specialchars($item->post_title) . "</option>";672 fb_parent_dropdown( $default, $item->ID, $level +1 );673 }674 } else {675 return false;676 }657 global $wpdb; 658 659 $albums_page = get_option('fb_albums_page'); 660 661 $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" ); 662 663 if ( $items ) { 664 foreach ( $items as $item ) { 665 $pad = str_repeat( ' ', $level * 3 ); 666 if ( $item->ID == $default) 667 $current = ' selected="selected"'; 668 else 669 $current = ''; 670 671 echo "\n\t<option value='$item->ID'$current>$pad " . wp_specialchars($item->post_title) . "</option>"; 672 fb_parent_dropdown( $default, $item->ID, $level +1 ); 673 } 674 } else { 675 return false; 676 } 677 677 } 678 678 679 679 function fb_days_used() { 680 global $wpdb;681 $status = $wpdb->get_row("SHOW TABLE STATUS FROM ".DB_NAME." WHERE `Name` = '".FB_ALBUM_TABLE."'", ARRAY_A);682 $created = $status['Create_time'];683 $days = ceil((time() - strtotime($created)) / (60 * 60 * 24));684 return $days > 2190 || $days < 0 ? 0 : $days;680 global $wpdb; 681 $status = $wpdb->get_row("SHOW TABLE STATUS FROM ".DB_NAME." WHERE `Name` = '".FB_ALBUM_TABLE."'", ARRAY_A); 682 $created = $status['Create_time']; 683 $days = ceil((time() - strtotime($created)) / (60 * 60 * 24)); 684 return $days > 2190 || $days < 0 ? 0 : $days; 685 685 } 686 686 687 687 function fb_cron_url() { 688 $secret = get_option('fb_secret');689 if(!$secret) {690 $secret = substr(md5(uniqid(rand(), true)), 0, 12);691 update_option('fb_secret', $secret);692 }693 return FB_PLUGIN_URL.'cron.php?secret='.$secret.'&update';688 $secret = get_option('fb_secret'); 689 if(!$secret) { 690 $secret = substr(md5(uniqid(rand(), true)), 0, 12); 691 update_option('fb_secret', $secret); 692 } 693 return FB_PLUGIN_URL.'cron.php?secret='.$secret.'&update'; 694 694 } 695 695 … … 699 699 700 700 function fb_get_album($album_id = 0, $user_id = null, $displayed_only = false) { 701 global $wpdb;702 703 $query = 'SELECT * FROM '.FB_ALBUM_TABLE.' ';704 $where = '';705 706 if($album_id || $user_id || $displayed_only)707 $query .= "WHERE ";708 709 if($album_id) {710 $query .= "aid = $album_id ";711 $array = $wpdb->get_results($query, ARRAY_A);712 return $array[0];713 }714 if($user_id) {715 if($where) $where .= "AND ";716 $where .= "owner = $user_id ";717 }718 if($displayed_only) {719 if($where) $where .= "AND ";720 $where .= "hidden = 0 ";721 }722 723 $query .= $where."ORDER BY ordinal DESC";724 725 $results = $wpdb->get_results($query, ARRAY_A);726 727 return $results;701 global $wpdb; 702 703 $query = 'SELECT * FROM '.FB_ALBUM_TABLE.' '; 704 $where = ''; 705 706 if($album_id || $user_id || $displayed_only) 707 $query .= "WHERE "; 708 709 if($album_id) { 710 $query .= "aid = $album_id "; 711 $array = $wpdb->get_results($query, ARRAY_A); 712 return $array[0]; 713 } 714 if($user_id) { 715 if($where) $where .= "AND "; 716 $where .= "owner = $user_id "; 717 } 718 if($displayed_only) { 719 if($where) $where .= "AND "; 720 $where .= "hidden = 0 "; 721 } 722 723 $query .= $where."ORDER BY ordinal DESC"; 724 725 $results = $wpdb->get_results($query, ARRAY_A); 726 727 return $results; 728 728 } 729 729 730 730 function fb_get_album_id($page_id) { 731 global $wpdb;732 return $wpdb->get_var("SELECT aid FROM ".FB_ALBUM_TABLE." WHERE page_id = $page_id");731 global $wpdb; 732 return $wpdb->get_var("SELECT aid FROM ".FB_ALBUM_TABLE." WHERE page_id = $page_id"); 733 733 } 734 734 735 735 function fb_update_album_order($order) { 736 global $wpdb;737 $order = array_reverse(explode(',', $order));738 foreach($order as $key=>$value) {739 $wpdb->query('UPDATE '.FB_ALBUM_TABLE.' SET ordinal = '.$key.' WHERE aid = '.$value.' LIMIT 1');740 }736 global $wpdb; 737 $order = array_reverse(explode(',', $order)); 738 foreach($order as $key=>$value) { 739 $wpdb->query('UPDATE '.FB_ALBUM_TABLE.' SET ordinal = '.$key.' WHERE aid = '.$value.' LIMIT 1'); 740 } 741 741 } 742 742 743 743 function fb_reset_album_order() { 744 global $wpdb;745 $albums = $wpdb->get_results('SELECT aid FROM '.FB_ALBUM_TABLE.' ORDER BY modified ASC', ARRAY_A);746 if(!$albums)747 return false;748 foreach($albums as $key=>$album) {749 $wpdb->query('UPDATE '.FB_ALBUM_TABLE.' SET ordinal = '.$key.' WHERE aid = '.$album['aid']);750 }751 return true;744 global $wpdb; 745 $albums = $wpdb->get_results('SELECT aid FROM '.FB_ALBUM_TABLE.' ORDER BY modified ASC', ARRAY_A); 746 if(!$albums) 747 return false; 748 foreach($albums as $key=>$album) { 749 $wpdb->query('UPDATE '.FB_ALBUM_TABLE.' SET ordinal = '.$key.' WHERE aid = '.$album['aid']); 750 } 751 return true; 752 752 } 753 753 754 754 function fb_remove_all() { 755 global $wpdb;756 $pages = $wpdb->get_results('SELECT ID FROM '.FB_POSTS_TABLE.' WHERE post_parent = '.get_option('fb_albums_page'), ARRAY_A);757 if($pages) {758 foreach($pages as $page) {759 // I would use the wp_delete_post function here but I'm getting a strange error760 $wpdb->query('DELETE FROM '.FB_POSTS_TABLE.' WHERE ID = '.$page['ID']);761 }762 }763 $wpdb->query('DELETE FROM '.FB_ALBUM_TABLE);764 $wpdb->query('DELETE FROM '.FB_PHOTO_TABLE);765 return;755 global $wpdb; 756 $pages = $wpdb->get_results('SELECT ID FROM '.FB_POSTS_TABLE.' WHERE post_parent = '.get_option('fb_albums_page'), ARRAY_A); 757 if($pages) { 758 foreach($pages as $page) { 759 // I would use the wp_delete_post function here but I'm getting a strange error 760 $wpdb->query('DELETE FROM '.FB_POSTS_TABLE.' WHERE ID = '.$page['ID']); 761 } 762 } 763 $wpdb->query('DELETE FROM '.FB_ALBUM_TABLE); 764 $wpdb->query('DELETE FROM '.FB_PHOTO_TABLE); 765 return; 766 766 } 767 767 768 768 function fb_get_next_ordinal() { 769 global $wpdb;770 $highest = $wpdb->get_var('SELECT ordinal FROM '.FB_ALBUM_TABLE.' ORDER BY ordinal DESC LIMIT 1');771 return ($highest + 1);769 global $wpdb; 770 $highest = $wpdb->get_var('SELECT ordinal FROM '.FB_ALBUM_TABLE.' ORDER BY ordinal DESC LIMIT 1'); 771 return ($highest + 1); 772 772 } 773 773 774 774 function fb_toggle_album_hiding($id) { 775 global $wpdb;776 $old = $wpdb->get_var('SELECT hidden FROM '.FB_ALBUM_TABLE.' WHERE aid = '.$id);777 $new = ($old == 1) ? 0 : 1;778 $wpdb->query('UPDATE '.FB_ALBUM_TABLE.' SET hidden = '.$new.' WHERE aid = '.$id);779 return true;775 global $wpdb; 776 $old = $wpdb->get_var('SELECT hidden FROM '.FB_ALBUM_TABLE.' WHERE aid = '.$id); 777 $new = ($old == 1) ? 0 : 1; 778 $wpdb->query('UPDATE '.FB_ALBUM_TABLE.' SET hidden = '.$new.' WHERE aid = '.$id); 779 return true; 780 780 } 781 781 782 782 function fb_get_photos($album_id = 0) { 783 global $wpdb;784 785 $query = 'SELECT * FROM '.FB_PHOTO_TABLE.' ';786 if($album_id != 0) $query .= "WHERE aid = $album_id ";787 $query .= "ORDER BY ordinal ASC"; 788 $photos = $wpdb->get_results($query, ARRAY_A);789 790 return $photos;783 global $wpdb; 784 785 $query = 'SELECT * FROM '.FB_PHOTO_TABLE.' '; 786 if($album_id != 0) $query .= "WHERE aid = $album_id "; 787 $query .= "ORDER BY ordinal ASC"; 788 $photos = $wpdb->get_results($query, ARRAY_A); 789 790 return $photos; 791 791 } 792 792 793 793 function fb_get_photo($id, $size = null) { 794 global $wpdb;795 if(!is_numeric($id)) return false;796 $query = 'SELECT * FROM '.FB_PHOTO_TABLE.' WHERE pid = '.$id;797 $photo = $wpdb->get_row($query, ARRAY_A);798 switch ($size) {799 case 'small':800 return $photo['src_small'];801 break;802 case 'thumb':803 return $photo['src'];804 break;805 case 'full':806 return $photo['src_big'];807 break;808 default:809 return $photo;810 break;811 }794 global $wpdb; 795 if(!is_numeric($id)) return false; 796 $query = 'SELECT * FROM '.FB_PHOTO_TABLE.' WHERE pid = '.$id; 797 $photo = $wpdb->get_row($query, ARRAY_A); 798 switch ($size) { 799 case 'small': 800 return $photo['src_small']; 801 break; 802 case 'thumb': 803 return $photo['src']; 804 break; 805 case 'full': 806 return $photo['src_big']; 807 break; 808 default: 809 return $photo; 810 break; 811 } 812 812 } 813 813 814 814 function fb_get_random_photos($count) { 815 global $wpdb;816 $query = "SELECT ".FB_PHOTO_TABLE.".link, pid, src, src_big, src_small, caption817 FROM ".FB_PHOTO_TABLE.", ".FB_ALBUM_TABLE."818 WHERE ".FB_PHOTO_TABLE.".aid = ".FB_ALBUM_TABLE.".aid AND ".FB_ALBUM_TABLE.".hidden = 0819 ORDER BY rand() LIMIT ".$count;820 $photos = $wpdb->get_results($query, ARRAY_A); 821 for($i = 0; $i < count($photos); $i++) {822 $photos[$i]['link'] = fb_get_photo_link($photos[$i]['pid']);823 }824 return $photos;815 global $wpdb; 816 $query = "SELECT ".FB_PHOTO_TABLE.".link, pid, src, src_big, src_small, caption 817 FROM ".FB_PHOTO_TABLE.", ".FB_ALBUM_TABLE." 818 WHERE ".FB_PHOTO_TABLE.".aid = ".FB_ALBUM_TABLE.".aid AND ".FB_ALBUM_TABLE.".hidden = 0 819 ORDER BY rand() LIMIT ".$count; 820 $photos = $wpdb->get_results($query, ARRAY_A); 821 for($i = 0; $i < count($photos); $i++) { 822 $photos[$i]['link'] = fb_get_photo_link($photos[$i]['pid']); 823 } 824 return $photos; 825 825 } 826 826 827 827 function fb_get_recent_photos($count) { 828 global $wpdb;829 $photos = $wpdb->get_results('SELECT * FROM '.FB_PHOTO_TABLE.' ORDER BY created DESC LIMIT '.$count, ARRAY_A); 830 for($i = 0; $i < count($photos); $i++) {831 $photos[$i]['link'] = fb_get_photo_link($photos[$i]);832 }833 return $photos;834 } 835 836 function fb_get_photo_link($photo) { // accepts either photo id or array of photo837 if(!is_array($photo)) {838 $photo = fb_get_photo($photo);839 }840 $album = fb_get_album($photo['aid']);841 $page_id = $album['page_id'];842 $page_link = get_permalink($page_id);843 $number_cols = get_option('fb_number_cols');844 $number_rows = get_option('fb_number_rows');845 if($number_rows == 0) $number_rows = ceil($photo_count / $number_cols);846 $photos_per_page = $number_cols * $number_rows;847 $album_p = $photos_per_page != 0 ? floor(($photo['ordinal']+1) / $photos_per_page)+1 : 1;848 switch (get_option('fb_style')) {849 case 'lightbox':850 $page_link .= strstr($page_link, '?') ? '&' : '?';851 $page_link .= 'album_p='.$album_p;852 $page_link .= '#photo'.($photo['ordinal']); 853 break;854 case 'embedded':855 $page_link .= strstr($page_link, '?') ? '&' : '?';856 $page_link .= 'photo='.($photo['ordinal']);857 break;858 }859 return htmlentities($page_link);828 global $wpdb; 829 $photos = $wpdb->get_results('SELECT * FROM '.FB_PHOTO_TABLE.' ORDER BY created DESC LIMIT '.$count, ARRAY_A); 830 for($i = 0; $i < count($photos); $i++) { 831 $photos[$i]['link'] = fb_get_photo_link($photos[$i]); 832 } 833 return $photos; 834 } 835 836 function fb_get_photo_link($photo) { // accepts either photo id or array of photo 837 if(!is_array($photo)) { 838 $photo = fb_get_photo($photo); 839 } 840 $album = fb_get_album($photo['aid']); 841 $page_id = $album['page_id']; 842 $page_link = get_permalink($page_id); 843 $number_cols = get_option('fb_number_cols'); 844 $number_rows = get_option('fb_number_rows'); 845 if($number_rows == 0) $number_rows = ceil($photo_count / $number_cols); 846 $photos_per_page = $number_cols * $number_rows; 847 $album_p = $photos_per_page != 0 ? floor(($photo['ordinal']+1) / $photos_per_page)+1 : 1; 848 switch (get_option('fb_style')) { 849 case 'lightbox': 850 $page_link .= strstr($page_link, '?') ? '&' : '?'; 851 $page_link .= 'album_p='.$album_p; 852 $page_link .= '#photo'.($photo['ordinal']); 853 break; 854 case 'embedded': 855 $page_link .= strstr($page_link, '?') ? '&' : '?'; 856 $page_link .= 'photo='.($photo['ordinal']); 857 break; 858 } 859 return htmlentities($page_link); 860 860 } 861 861 862 862 function fb_hidden_pages($array = array()) { 863 global $wpdb;864 865 if(get_option('fb_hide_pages') == 1) {866 $query = 'SELECT page_id FROM '.FB_ALBUM_TABLE;867 } else {868 $query = 'SELECT page_id FROM '.FB_ALBUM_TABLE.' WHERE hidden = 1';869 }870 871 $results = $wpdb->get_results($query, ARRAY_A);872 if(!$results) return $array;873 874 foreach($results as $result) {875 $array[] = $result['page_id'];876 }877 return $array;863 global $wpdb; 864 865 if(get_option('fb_hide_pages') == 1) { 866 $query = 'SELECT page_id FROM '.FB_ALBUM_TABLE; 867 } else { 868 $query = 'SELECT page_id FROM '.FB_ALBUM_TABLE.' WHERE hidden = 1'; 869 } 870 871 $results = $wpdb->get_results($query, ARRAY_A); 872 if(!$results) return $array; 873 874 foreach($results as $result) { 875 $array[] = $result['page_id']; 876 } 877 return $array; 878 878 } 879 879 … … 883 883 884 884 function fb_display($content) { 885 global $wpdb;886 887 // get variables to check if this is part of fotobook888 $post= $GLOBALS['post'];889 $post_id= $post->ID;890 $post_parent= $post->post_parent;891 $albums_page_id= get_option('fb_albums_page');892 893 // don't show password protected pages894 if (!empty($post->post_password) && $_COOKIE['wp-postpass_'. COOKIEHASH] != $post->post_password) {895 return $content;896 }897 898 if($post_id != $albums_page_id && $post_parent != $albums_page_id) {899 return $content;900 }901 902 // display all albums903 if($post_id == $albums_page_id) {904 return fb_display_main($content);905 }906 907 // display individual albums908 if($post_parent == $albums_page_id && $post_parent != 0) {909 if(isset($_GET['photo']) && get_option('fb_style') == 'embedded') {910 return fb_display_photo($content, $post_id, $_GET['photo']);911 } else {912 return fb_display_album($content, $post_id);913 }914 }885 global $wpdb; 886 887 // get variables to check if this is part of fotobook 888 $post = $GLOBALS['post']; 889 $post_id = $post->ID; 890 $post_parent = $post->post_parent; 891 $albums_page_id = get_option('fb_albums_page'); 892 893 // don't show password protected pages 894 if (!empty($post->post_password) && $_COOKIE['wp-postpass_'. COOKIEHASH] != $post->post_password) { 895 return $content; 896 } 897 898 if($post_id != $albums_page_id && $post_parent != $albums_page_id) { 899 return $content; 900 } 901 902 // display all albums 903 if($post_id == $albums_page_id) { 904 return fb_display_main($content); 905 } 906 907 // display individual albums 908 if($post_parent == $albums_page_id && $post_parent != 0) { 909 if(isset($_GET['photo']) && get_option('fb_style') == 'embedded') { 910 return fb_display_photo($content, $post_id, $_GET['photo']); 911 } else { 912 return fb_display_album($content, $post_id); 913 } 914 } 915 915 } 916 916 917 917 function fb_display_main($content) { 918 remove_filter('the_content','wpautop');919 920 // buffer the output921 ob_start();922 923 // get albums924 $albums = fb_get_album(null, null, true);925 $album_count = sizeof($albums);926 if(!$albums) {927 echo "<p>There are no albums.</p>";928 return;929 }930 $album_link = get_permalink(get_option('fb_albums_page'));931 array_unshift($albums, ''); // moves all the keys down932 unset($albums[0]);933 934 // determine pagination935 $albums_per_page = get_option('fb_albums_per_page');936 if($albums_per_page == 0) {937 $albums_per_page = $album_count;938 }939 $page_count = ceil($album_count / $albums_per_page);940 $curr_page = $_GET['album_p'] <= $page_count && $_GET['album_p'] > 0 ? $_GET['album_p'] : 1;941 $first_album = (($curr_page-1) * $albums_per_page) + 1;942 $last_album = $first_album + $albums_per_page - 1;943 $last_album = $last_album > $album_count ? $album_count : $last_album;944 945 // generate pagination946 if($page_count == 1) {947 $prev_link = ''; $next_link = ''; $pagination = ' ';948 } else {949 $prev_link = $curr_page > 1 ? $curr_page - 1 : false;950 if($prev_link !== false)951 $prev_link = $album_link.(strstr($album_link, '?') ? '&album_p='.($prev_link) : '?album_p='.($prev_link));952 $next_link = $curr_page + 1 <= $page_count ? $curr_page + 1 : false;953 if($next_link)954 $next_link = $album_link.(strstr($album_link, '?') ? '&album_p='.($next_link) : '?album_p='.($next_link)); 955 $pagination = '';956 for($i = 1; $i <= $page_count; $i++) {957 if($i == $curr_page)958 $pagination .= '<b>'.$i.'</b>';959 else {960 $link = $album_link.(strstr($album_link, '?') ? '&album_p='.$i : '?album_p='.$i);961 $pagination .= "<a href='$link'>".($i)."</a>";962 }963 }964 }965 966 // now get rid of all albums in the array that aren't displayed on this page967 $albums = array_slice_preserve_keys($albums, $first_album-1, $albums_per_page);968 foreach($albums as $key=>$album) {969 $albums[$key]['link']= get_permalink($albums[$key]['page_id']);970 $albums[$key]['thumb'] = fb_get_photo($albums[$key]['cover_pid'], 'thumb');971 }972 973 include(FB_STYLE_PATH.'main.php');974 ?>975 <div id="fotobook-credits" style="text-align: right;">976 <small>Powered by <a href="http://www.aaronharp.com/dev/wp-fotobook/">Fotobook</a></small>977 </div>918 remove_filter('the_content','wpautop'); 919 920 // buffer the output 921 ob_start(); 922 923 // get albums 924 $albums = fb_get_album(null, null, true); 925 $album_count = sizeof($albums); 926 if(!$albums) { 927 echo "<p>There are no albums.</p>"; 928 return; 929 } 930 $album_link = get_permalink(get_option('fb_albums_page')); 931 array_unshift($albums, ''); // moves all the keys down 932 unset($albums[0]); 933 934 // determine pagination 935 $albums_per_page = get_option('fb_albums_per_page'); 936 if($albums_per_page == 0) { 937 $albums_per_page = $album_count; 938 } 939 $page_count = ceil($album_count / $albums_per_page); 940 $curr_page = $_GET['album_p'] <= $page_count && $_GET['album_p'] > 0 ? $_GET['album_p'] : 1; 941 $first_album = (($curr_page-1) * $albums_per_page) + 1; 942 $last_album = $first_album + $albums_per_page - 1; 943 $last_album = $last_album > $album_count ? $album_count : $last_album; 944 945 // generate pagination 946 if($page_count == 1) { 947 $prev_link = ''; $next_link = ''; $pagination = ' '; 948 } else { 949 $prev_link = $curr_page > 1 ? $curr_page - 1 : false; 950 if($prev_link !== false) 951 $prev_link = $album_link.(strstr($album_link, '?') ? '&album_p='.($prev_link) : '?album_p='.($prev_link)); 952 $next_link = $curr_page + 1 <= $page_count ? $curr_page + 1 : false; 953 if($next_link) 954 $next_link = $album_link.(strstr($album_link, '?') ? '&album_p='.($next_link) : '?album_p='.($next_link)); 955 $pagination = ''; 956 for($i = 1; $i <= $page_count; $i++) { 957 if($i == $curr_page) 958 $pagination .= '<b>'.$i.'</b>'; 959 else { 960 $link = $album_link.(strstr($album_link, '?') ? '&album_p='.$i : '?album_p='.$i); 961 $pagination .= "<a href='$link'>".($i)."</a>"; 962 } 963 } 964 } 965 966 // now get rid of all albums in the array that aren't displayed on this page 967 $albums = array_slice_preserve_keys($albums, $first_album-1, $albums_per_page); 968 foreach($albums as $key=>$album) { 969 $albums[$key]['link'] = get_permalink($albums[$key]['page_id']); 970 $albums[$key]['thumb'] = fb_get_photo($albums[$key]['cover_pid'], 'thumb'); 971 } 972 973 include(FB_STYLE_PATH.'main.php'); 974 ?> 975 <div id="fotobook-credits" style="text-align: right;"> 976 <small>Powered by <a href="http://www.aaronharp.com/dev/wp-fotobook/">Fotobook</a></small> 977 </div> 978 978 <?php 979 // now capture the buffer and add it to $content980 $content .= ob_get_clean();981 return $content;979 // now capture the buffer and add it to $content 980 $content .= ob_get_clean(); 981 return $content; 982 982 } 983 983 984 984 function fb_display_album($content, $page_id) { 985 // turn off content filter so that <p> and <br> tags aren't added986 remove_filter('the_content','wpautop');987 988 // buffer the output989 // ob_start();990 991 $albums_page_link = htmlentities(get_permalink(get_option('fb_albums_page')));992 $page_link = get_permalink($page_id); 993 $album_id = fb_get_album_id($page_id);994 $album = fb_get_album($album_id);995 $photos = fb_get_photos($album_id);996 $photo_count = sizeof($photos);997 if($photo_count == 0) {998 echo '<p>This album is empty.</p>';999 return false;1000 }1001 array_unshift($photos, ''); // moves all the keys down1002 unset($photos[0]);1003 1004 // check if page is hidden1005 if($album['hidden'] == 1) {1006 $message = '<p>This album is not available. <a href="'.get_permalink(get_option('fb_albums_page')).'">Return to albums</a>.</p>';1007 return $message.$content;1008 }1009 1010 // html encode all captions1011 foreach($photos as $key=>$photo) {1012 $photos[$key]['caption'] = function_exists('seems_utf8') && seems_utf8($photo['caption'])1013 ? htmlentities($photo['caption'], ENT_QUOTES, 'utf-8')1014 : htmlentities($photo['caption'], ENT_QUOTES);1015 }1016 1017 $thumb_size = get_option('fb_thumb_size');1018 $number_cols = get_option('fb_number_cols');1019 $number_rows = get_option('fb_number_rows') == 0 ? ceil($photo_count / $number_cols) : get_option('fb_number_rows');1020 $photos_per_page = $number_cols * $number_rows;1021 1022 $page_count = ceil($photo_count / $photos_per_page);1023 $curr_page = ($_GET['album_p'] <= $page_count) && ($_GET['album_p'] > 0) ? $_GET['album_p'] : 1;1024 $first_photo = ($curr_page - 1) * $photos_per_page + 1;1025 $last_photo = $first_photo + $photos_per_page - 1;1026 $last_photo = $last_photo > $photo_count ? $photo_count : $last_photo;1027 $rows_curr_page = ceil(($last_photo - $first_photo + 1) / $number_cols);1028 1029 // generate pagination1030 if($page_count == 1) {1031 $prev_link = ''; $next_link = ''; $pagination = ' ';1032 } else {1033 $prev_link = $curr_page > 1 ? $curr_page - 1 : false;1034 if($prev_link !== false)1035 $prev_link = $page_link.(strstr($page_link, '?') ? '&album_p='.($prev_link) : '?album_p='.($prev_link));1036 $next_link = $curr_page < $page_count ? $curr_page + 1 : null;1037 if($next_link)1038 $next_link = $page_link.(strstr($page_link, '?') ? '&album_p='.($next_link) : '?album_p='.($next_link)); 1039 $pagination = '';1040 for($i = 1; $i <= $page_count; $i++) {1041 if($i == $curr_page)1042 $pagination .= '<b>'.$i.'</b>';1043 else {1044 $link = $page_link.(strstr($page_link, '?') ? '&album_p='.$i : '?album_p='.$i);1045 $pagination .= "<a href='$link'>".($i)."</a>";1046 }1047 }1048 }1049 1050 // album info1051 $description = $album['description'];1052 $location = $album['location'];1053 1054 // add hidden links for all images before so that next and previous1055 // buttons in lightbox will display these images as well1056 $hidden_top = ''; $hidden_bottom = '';1057 for($i = 1; $i <= $first_photo; $i++) {1058 $hidden_top .= "<a href=\"{$photos[$i]['src_big']}\" rel=\"lightbox[fotobook]\" title=\"{$photos[$i]['caption']}\"></a>";1059 }1060 for($i = $last_photo+1; $i <= $photo_count; $i++) {1061 $hidden_bottom .= "<a href=\"{$photos[$i]['src_big']}\" rel=\"lightbox[fotobook]\" title=\"{$photos[$i]['caption']}\"></a>";1062 }1063 1064 // now get rid of all photos in the array that aren't displayed on this page1065 $photos = array_slice_preserve_keys($photos, $first_photo-1, $photos_per_page);1066 1067 ?>1068 <br />1069 <p style="display: none"><?php echo $hidden_top ?></p>1070 <?php include(FB_STYLE_PATH.'album.php') ?>1071 <p style="display: none"><?php echo $hidden_bottom ?></p>985 // turn off content filter so that <p> and <br> tags aren't added 986 remove_filter('the_content','wpautop'); 987 988 // buffer the output 989 // ob_start(); 990 991 $albums_page_link = htmlentities(get_permalink(get_option('fb_albums_page'))); 992 $page_link = get_permalink($page_id); 993 $album_id = fb_get_album_id($page_id); 994 $album = fb_get_album($album_id); 995 $photos = fb_get_photos($album_id); 996 $photo_count = sizeof($photos); 997 if($photo_count == 0) { 998 echo '<p>This album is empty.</p>'; 999 return false; 1000 } 1001 array_unshift($photos, ''); // moves all the keys down 1002 unset($photos[0]); 1003 1004 // check if page is hidden 1005 if($album['hidden'] == 1) { 1006 $message = '<p>This album is not available. <a href="'.get_permalink(get_option('fb_albums_page')).'">Return to albums</a>.</p>'; 1007 return $message.$content; 1008 } 1009 1010 // html encode all captions 1011 foreach($photos as $key=>$photo) { 1012 $photos[$key]['caption'] = function_exists('seems_utf8') && seems_utf8($photo['caption']) 1013 ? htmlentities($photo['caption'], ENT_QUOTES, 'utf-8') 1014 : htmlentities($photo['caption'], ENT_QUOTES); 1015 } 1016 1017 $thumb_size = get_option('fb_thumb_size'); 1018 $number_cols = get_option('fb_number_cols'); 1019 $number_rows = get_option('fb_number_rows') == 0 ? ceil($photo_count / $number_cols) : get_option('fb_number_rows'); 1020 $photos_per_page = $number_cols * $number_rows; 1021 1022 $page_count = ceil($photo_count / $photos_per_page); 1023 $curr_page = ($_GET['album_p'] <= $page_count) && ($_GET['album_p'] > 0) ? $_GET['album_p'] : 1; 1024 $first_photo = ($curr_page - 1) * $photos_per_page + 1; 1025 $last_photo = $first_photo + $photos_per_page - 1; 1026 $last_photo = $last_photo > $photo_count ? $photo_count : $last_photo; 1027 $rows_curr_page = ceil(($last_photo - $first_photo + 1) / $number_cols); 1028 1029 // generate pagination 1030 if($page_count == 1) { 1031 $prev_link = ''; $next_link = ''; $pagination = ' '; 1032 } else { 1033 $prev_link = $curr_page > 1 ? $curr_page - 1 : false; 1034 if($prev_link !== false) 1035 $prev_link = $page_link.(strstr($page_link, '?') ? '&album_p='.($prev_link) : '?album_p='.($prev_link)); 1036 $next_link = $curr_page < $page_count ? $curr_page + 1 : null; 1037 if($next_link) 1038 $next_link = $page_link.(strstr($page_link, '?') ? '&album_p='.($next_link) : '?album_p='.($next_link)); 1039 $pagination = ''; 1040 for($i = 1; $i <= $page_count; $i++) { 1041 if($i == $curr_page) 1042 $pagination .= '<b>'.$i.'</b>'; 1043 else { 1044 $link = $page_link.(strstr($page_link, '?') ? '&album_p='.$i : '?album_p='.$i); 1045 $pagination .= "<a href='$link'>".($i)."</a>"; 1046 } 1047 } 1048 } 1049 1050 // album info 1051 $description = $album['description']; 1052 $location = $album['location']; 1053 1054 // add hidden links for all images before so that next and previous 1055 // buttons in lightbox will display these images as well 1056 $hidden_top = ''; $hidden_bottom = ''; 1057 for($i = 1; $i <= $first_photo; $i++) { 1058 $hidden_top .= "<a href=\"{$photos[$i]['src_big']}\" rel=\"lightbox[fotobook]\" title=\"{$photos[$i]['caption']}\"></a>"; 1059 } 1060 for($i = $last_photo+1; $i <= $photo_count; $i++) { 1061 $hidden_bottom .= "<a href=\"{$photos[$i]['src_big']}\" rel=\"lightbox[fotobook]\" title=\"{$photos[$i]['caption']}\"></a>"; 1062 } 1063 1064 // now get rid of all photos in the array that aren't displayed on this page 1065 $photos = array_slice_preserve_keys($photos, $first_photo-1, $photos_per_page); 1066 1067 ?> 1068 <br /> 1069 <p style="display: none"><?php echo $hidden_top ?></p> 1070 <?php include(FB_STYLE_PATH.'album.php') ?> 1071 <p style="display: none"><?php echo $hidden_bottom ?></p> 1072 1072 <?php 1073 //$content .= ob_get_clean();1074 return $content;1073 //$content .= ob_get_clean(); 1074 return $content; 1075 1075 } 1076 1076 1077 1077 function fb_display_photo($content, $page_id, $photo) { 1078 // turn off content filter so that <p> and <br> tags aren't added1079 remove_filter('the_content','wpautop');1080 1081 // buffer the output1082 ob_start(); 1083 1084 // get photos1085 $photos = fb_get_photos(fb_get_album_id($page_id));1086 $photo_count = sizeof($photos);1087 array_unshift($photos, ''); // moves all the keys down1088 unset($photos[0]); 1089 1090 // pagination1091 $page_link = get_permalink($page_id); 1092 $curr = ($photo <= $photo_count && $photo > 0) ? $photo : 1;1093 $next = ($curr + 1 <= $photo_count) ? $curr + 1 : false;1094 $prev = ($curr != 1) ? $curr - 1 : false;1095 if($next)1096 $next_link = $page_link.(strstr($page_link, '?') ? '&photo='.($next) : '?photo='.($next));1097 if($prev)1098 $prev_link = $page_link.(strstr($page_link, '?') ? '&photo='.($prev) : '?photo='.($prev));1099 $photo = $photos[$curr];1100 1101 // html encode caption1102 $photo['caption'] = function_exists('seems_utf8') && seems_utf8($photo['caption'])1103 ? htmlentities($photo['caption'], ENT_QUOTES, 'utf-8')1104 : htmlentities($photo['caption'], ENT_QUOTES);1105 1106 // get max width1107 $width = get_option('fb_embedded_width');1108 1109 include(FB_STYLE_PATH.'photo.php');1110 1111 $content .= ob_get_clean();1112 return $content;1078 // turn off content filter so that <p> and <br> tags aren't added 1079 remove_filter('the_content','wpautop'); 1080 1081 // buffer the output 1082 ob_start(); 1083 1084 // get photos 1085 $photos = fb_get_photos(fb_get_album_id($page_id)); 1086 $photo_count = sizeof($photos); 1087 array_unshift($photos, ''); // moves all the keys down 1088 unset($photos[0]); 1089 1090 // pagination 1091 $page_link = get_permalink($page_id); 1092 $curr = ($photo <= $photo_count && $photo > 0) ? $photo : 1; 1093 $next = ($curr + 1 <= $photo_count) ? $curr + 1 : false; 1094 $prev = ($curr != 1) ? $curr - 1 : false; 1095 if($next) 1096 $next_link = $page_link.(strstr($page_link, '?') ? '&photo='.($next) : '?photo='.($next)); 1097 if($prev) 1098 $prev_link = $page_link.(strstr($page_link, '?') ? '&photo='.($prev) : '?photo='.($prev)); 1099 $photo = $photos[$curr]; 1100 1101 // html encode caption 1102 $photo['caption'] = function_exists('seems_utf8') && seems_utf8($photo['caption']) 1103 ? htmlentities($photo['caption'], ENT_QUOTES, 'utf-8') 1104 : htmlentities($photo['caption'], ENT_QUOTES); 1105 1106 // get max width 1107 $width = get_option('fb_embedded_width'); 1108 1109 include(FB_STYLE_PATH.'photo.php'); 1110 1111 $content .= ob_get_clean(); 1112 return $content; 1113 1113 } 1114 1114 1115 1115 function fb_display_manage_list($message = '') { 1116 $albums = fb_get_album();1117 1118 if($message != ''): ?>1119 <div id="fb-message" class="updated fade" style="display: none"><p><?php echo $message ?></p></div>1120 <script>1121 Effect.SlideDown('fb-message');1122 setTimeout('Effect.SlideUp(\'fb-message\')', 5000);1123 </script>1124 <?php endif; ?>1125 1126 <?php if($albums) { ?>1127 <ul id="fb-manage-list">1128 <?php1129 for($i = 0; $i < sizeof($albums); $i++):1130 $album = $albums[$i];1131 $thumb = fb_get_photo($album['cover_pid'], 'small');1132 $class = ($album['hidden'] == 1) ? 'disabled' : '';1133 ?>1134 <li class="<?php echo $class ?>" id="album_<?php echo $album['aid'] ?>">1135 <div class="thumb" style="background-image:url(<?php echo $thumb ?>);"></div>1136 <div>1137 <h3><?php echo $album['name'] ?><small style="font-weight: normal"></h3>1138 <div class="description">1139 <?php echo $album['size'] ?> Photos</small><br />1140 Created: <?php echo mysql2date('m-d-Y', $album['created']) ?>, Modified: <?php echo mysql2date('m-d-Y', $album['modified']) ?><br />1141 <span>1142 <a href="<?php echo get_option('siteurl').'?page_id='.$album['page_id'] ?>" target="_blank">View</a>1143 <a href="#" onclick="toggleHidden(this, '<?php echo $album['aid'] ?>'); return false;"><?php echo $album['hidden'] ? 'Show' : 'Hide' ?></a>1144 </span>1145 </div>1146 </div>1147 <div style="clear: left"></div>1148 </li>1149 <?php endfor; ?> 1150 </ul>1151 <script language="javascript">1152 Sortable.create('fb-manage-list', { onUpdate: updateAlbumOrder, handle: 'handle' });1153 </script>1154 <?php } else { ?>1155 <p>There are no albums.</p>1156 <?php1157 }1116 $albums = fb_get_album(); 1117 1118 if($message != ''): ?> 1119 <div id="fb-message" class="updated fade" style="display: none"><p><?php echo $message ?></p></div> 1120 <script> 1121 Effect.SlideDown('fb-message'); 1122 setTimeout('Effect.SlideUp(\'fb-message\')', 5000); 1123 </script> 1124 <?php endif; ?> 1125 1126 <?php if($albums) { ?> 1127 <ul id="fb-manage-list"> 1128 <?php 1129 for($i = 0; $i < sizeof($albums); $i++): 1130 $album = $albums[$i]; 1131 $thumb = fb_get_photo($album['cover_pid'], 'small'); 1132 $class = ($album['hidden'] == 1) ? 'disabled' : ''; 1133 ?> 1134 <li class="<?php echo $class ?>" id="album_<?php echo $album['aid'] ?>"> 1135 <div class="thumb" style="background-image:url(<?php echo $thumb ?>);"></div> 1136 <div> 1137 <h3><?php echo $album['name'] ?><small style="font-weight: normal"></h3> 1138 <div class="description"> 1139 <?php echo $album['size'] ?> Photos</small><br /> 1140 Created: <?php echo mysql2date('m-d-Y', $album['created']) ?>, Modified: <?php echo mysql2date('m-d-Y', $album['modified']) ?><br /> 1141 <span> 1142 <a href="<?php echo get_option('siteurl').'?page_id='.$album['page_id'] ?>" target="_blank">View</a> 1143 <a href="#" onclick="toggleHidden(this, '<?php echo $album['aid'] ?>'); return false;"><?php echo $album['hidden'] ? 'Show' : 'Hide' ?></a> 1144 </span> 1145 </div> 1146 </div> 1147 <div style="clear: left"></div> 1148 </li> 1149 <?php endfor; ?> 1150 </ul> 1151 <script language="javascript"> 1152 Sortable.create('fb-manage-list', { onUpdate: updateAlbumOrder, handle: 'handle' }); 1153 </script> 1154 <?php } else { ?> 1155 <p>There are no albums.</p> 1156 <?php 1157 } 1158 1158 } 1159 1159 1160 1160 function fb_info_box() { 1161 ?> 1162 <div id="fb-info">1163 <h3>Info</h3>1164 <?php if(fb_days_used() >= 50): ?>1165 <p>Fotobook didn't write itself. Thought about <a href="<?php echo FB_DONATE ?>">donating</a> a few bucks?Come on, you've used it for <?php echo fb_days_used(); ?> days =).1166 <?php endif; ?>1167 <ul>1168 <li><a href="http://www.aaronharp.com/dev/wp-fotobook/">Fotobook Home</a></li>1169 <li><a href="http://www.facebook.com/board.php?uid=2254862517">Support Forum</a></li>1170 <li><a href="<?php echo FB_DONATE ?>">Donate</a></li>1171 <li><a href="http://www.dreamhost.com/r.cgi?275020/signup|fotobook">DreamHost</a></li>1172 <li><a href="http://www.aaronharp.com/dev/">Need a developer?</a></li>1173 </ul>1174 1175 </div>1161 ?> 1162 <div id="fb-info"> 1163 <h3>Info</h3> 1164 <?php if(fb_days_used() >= 50): ?> 1165 <p>Fotobook didn't write itself. Thought about <a href="<?php echo FB_DONATE ?>">donating</a> a few bucks? Come on, you've used it for <?php echo fb_days_used(); ?> days =). 1166 <?php endif; ?> 1167 <ul> 1168 <li><a href="http://www.aaronharp.com/dev/wp-fotobook/">Fotobook Home</a></li> 1169 <li><a href="http://www.facebook.com/board.php?uid=2254862517">Support Forum</a></li> 1170 <li><a href="<?php echo FB_DONATE ?>">Donate</a></li> 1171 <li><a href="http://www.dreamhost.com/r.cgi?275020/signup|fotobook">DreamHost</a></li> 1172 <li><a href="http://www.aaronharp.com/dev/">Need a developer?</a></li> 1173 </ul> 1174 1175 </div> 1176 1176 <?php 1177 1177 } 1178 1178 1179 1179 function fb_head() { 1180 $post = $GLOBALS['post'];1181 $albums_page = get_option('fb_albums_page');1182 if($post->ID == $albums_page || $post->post_parent == $albums_page) {1183 echo '<link rel="stylesheet" href="'.FB_STYLE_URL.'style.css" type="text/css" media="screen" charset="utf-8" />'."\r\n";1184 }1185 if(is_active_widget('fb_photos_widget')) {1186 echo '<link rel="stylesheet" href="'.FB_PLUGIN_URL.'styles/sidebar-style.css" type="text/css" media="screen" charset="utf-8" />'."\r\n";1187 echo '<script type="text/javascript" src="'.FB_PLUGIN_URL.'js/widget.js"></script>';1188 }1180 $post = $GLOBALS['post']; 1181 $albums_page = get_option('fb_albums_page'); 1182 if($post->ID == $albums_page || $post->post_parent == $albums_page) { 1183 echo '<link rel="stylesheet" href="'.FB_STYLE_URL.'style.css" type="text/css" media="screen" charset="utf-8" />'."\r\n"; 1184 } 1185 if(is_active_widget('fb_photos_widget')) { 1186 echo '<link rel="stylesheet" href="'.FB_PLUGIN_URL.'styles/sidebar-style.css" type="text/css" media="screen" charset="utf-8" />'."\r\n"; 1187 echo '<script type="text/javascript" src="'.FB_PLUGIN_URL.'js/widget.js"></script>'; 1188 } 1189 1189 } 1190 1190 … … 1194 1194 1195 1195 function fb_add_upload_tab($tabs) { 1196 // 0 => tab display name, 1 => required cap, 2 => function that produces tab content, 3 => total number objects OR array(total, objects per page), 4 => add_query_args1197 $tab = array('fotobook' => array('Fotobook', 'upload_files', 'fb_upload_tab', 0));1198 return array_merge($tabs, $tab);1196 // 0 => tab display name, 1 => required cap, 2 => function that produces tab content, 3 => total number objects OR array(total, objects per page), 4 => add_query_args 1197 $tab = array('fotobook' => array('Fotobook', 'upload_files', 'fb_upload_tab', 0)); 1198 return array_merge($tabs, $tab); 1199 1199 } 1200 1200 1201 1201 function fb_upload_tab() { 1202 // generate link without aid variable1203 $vars = explode('&', $_SERVER['QUERY_STRING']);1204 if(stristr($vars[count($vars)-1], 'aid')) {1205 unset($vars[count($vars)-1]);1206 }1207 $link = 'upload.php?'.implode('&', $vars);1208 echo '<br />';1209 fb_photos_tab($link);1202 // generate link without aid variable 1203 $vars = explode('&', $_SERVER['QUERY_STRING']); 1204 if(stristr($vars[count($vars)-1], 'aid')) { 1205 unset($vars[count($vars)-1]); 1206 } 1207 $link = 'upload.php?'.implode('&', $vars); 1208 echo '<br />'; 1209 fb_photos_tab($link); 1210 1210 } 1211 1211 1212 1212 function fb_add_media_tab($tabs) { 1213 if(isset($_GET['type']) && $_GET['type'] == 'image')1214 $tabs['fotobook'] = 'Fotobook';1215 return $tabs;1213 if(isset($_GET['type']) && $_GET['type'] == 'image') 1214 $tabs['fotobook'] = 'Fotobook'; 1215 return $tabs; 1216 1216 } 1217 1217 1218 1218 function media_upload_fotobook() { 1219 global $wpdb, $wp_query, $wp_locale, $type, $tab, $post_mime_types;1220 return wp_iframe( 'media_upload_fotobook_tab', $errors );1219 global $wpdb, $wp_query, $wp_locale, $type, $tab, $post_mime_types; 1220 return wp_iframe( 'media_upload_fotobook_tab', $errors ); 1221 1221 } 1222 1222 1223 1223 function media_upload_fotobook_tab($errors) { 1224 // generate link without aid variable1225 $vars = explode('&', $_SERVER['QUERY_STRING']);1226 if(stristr($vars[count($vars)-1], 'aid')) {1227 unset($vars[count($vars)-1]);1228 }1229 $link = 'media-upload.php?'.implode('&', $vars);1230 media_upload_header();1231 fb_photos_tab($link);1224 // generate link without aid variable 1225 $vars = explode('&', $_SERVER['QUERY_STRING']); 1226 if(stristr($vars[count($vars)-1], 'aid')) { 1227 unset($vars[count($vars)-1]); 1228 } 1229 $link = 'media-upload.php?'.implode('&', $vars); 1230 media_upload_header(); 1231 fb_photos_tab($link); 1232 1232 } 1233 1233 1234 1234 function fb_photos_tab($link) { ?> 1235 <style type="text/css">1236 <?php include(FB_PLUGIN_PATH.'styles/admin-styles.css'); ?>1237 </style>1238 <form id="image-form">1239 <?php1240 if(isset($_GET['aid'])):1241 $album = fb_get_album($_GET['aid']);1242 $photos = fb_get_photos($_GET['aid']);1243 ?>1244 <script language="javascript">1245 var fbThumb; var fbFull; var fbLink; var fbCaption;1246 function findPos(obj) {1247 var curleft = curtop = 0;1248 if (obj.offsetParent) {1249 do {1250 curleft += obj.offsetLeft;1251 curtop += obj.offsetTop;1252 } while (obj = obj.offsetParent);1253 }1254 return [curleft,curtop];1255 }1256 function insertPopup(obj, thumb, full, link, caption) {1257 fbThumb = thumb; fbFull= full;1258 fbLink = link;fbCaption = caption;1259 var popup = document.getElementById('fb-insert-popup');1260 popup.style.display = 'block';1261 popup.style.left= findPos(obj)[0]+'px';1262 popup.style.top= findPos(obj)[1]+'px';1263 }1264 function insertPhoto(size) {1265 if(size == 'thumb') var src = fbThumb;1266 else var src = fbFull;1267 var html =1268 '<a href="'+fbLink+'" class="fb-photo">' +1269 '<img src="'+src+'" alt="'+fbCaption+'" />' +1270 '</a> '1271 var win = window.opener ? window.opener : window.dialogArguments;1272 if (!win) win = top;1273 tinyMCE = win.tinyMCE;1274 if (typeof tinyMCE != 'undefined' && tinyMCE.getInstanceById('content')) {1275 tinyMCE.selectedInstance.getWin().focus();1276 tinyMCE.execCommand('mceInsertContent', false, html);1277 } else win.edInsertContent(win.edCanvas, h);1278 document.getElementById('fb-insert-popup').style.display = 'none';1279 }1280 </script>1281 <h3><?php echo $album['name'] ?> <a href="<?php echo $link ?>" style="font-size: 11px">« Back to Albums</a></small></h2>1282 1283 <div id="fb-insert-popup">1284 Insert...<br />1285 <a href="#" onclick="insertPhoto('thumb'); return false;">Thumbnail</a><br />1286 <a href="#" onclick="insertPhoto('full'); return false;">Full</a><br />1287 <br /><a href="#" onclick="this.parentNode.style.display = 'none'; return false;">[close]</a>1288 </div>1289 1290 <ul id="fb-photos-tab">1291 <?php foreach($photos as $photo): ?>1292 <li>1293 <a href="#" onclick="insertPopup(this.parentNode, '<?php echo $photo['src'] ?>','<?php echo $photo['src_big'] ?>','<?php echo fb_get_photo_link($photo['pid']) ?>', '<?php echo addslashes($photo['caption']) ?>'); return false;">1294 <img src="<?php echo $photo['src']; ?>" />1295 </a>1296 </li> 1297 <?php endforeach; ?>1298 </ul>1299 <?php1300 else:1301 $albums = fb_get_album();1302 ?>1303 <h3>Select an Album</h3>1304 <ul id="fb-manage-list">1305 <?php1306 foreach($albums as $album):1307 $thumb = fb_get_photo($album['cover_pid'], 'small');1308 ?>1309 <li id="album_<?php echo $album['aid'] ?>" style="cursor: default">1310 <div class="thumb" style="background-image:url(<?php echo $thumb ?>);"></div>1311 <div>1312 <h3><a href="<?php echo $link ?>&aid=<?php echo $album['aid'] ?>"><?php echo $album['name'] ?></a></h3>1313 <div class="description">1314 <small style="font-weight: normal"><?php echo $album['size'] ?> Photos</small><br />1315 </div>1316 </div>1317 <div style="clear: both"></div>1318 </li>1319 <?php endforeach; ?>1320 </ul>1321 <?php endif; ?>1322 </form>1323 <?php1235 <style type="text/css"> 1236 <?php include(FB_PLUGIN_PATH.'styles/admin-styles.css'); ?> 1237 </style> 1238 <form id="image-form"> 1239 <?php 1240 if(isset($_GET['aid'])): 1241 $album = fb_get_album($_GET['aid']); 1242 $photos = fb_get_photos($_GET['aid']); 1243 ?> 1244 <script language="javascript"> 1245 var fbThumb; var fbFull; var fbLink; var fbCaption; 1246 function findPos(obj) { 1247 var curleft = curtop = 0; 1248 if (obj.offsetParent) { 1249 do { 1250 curleft += obj.offsetLeft; 1251 curtop += obj.offsetTop; 1252 } while (obj = obj.offsetParent); 1253 } 1254 return [curleft,curtop]; 1255 } 1256 function insertPopup(obj, thumb, full, link, caption) { 1257 fbThumb = thumb; fbFull = full; 1258 fbLink = link; fbCaption = caption; 1259 var popup = document.getElementById('fb-insert-popup'); 1260 popup.style.display = 'block'; 1261 popup.style.left = findPos(obj)[0]+'px'; 1262 popup.style.top = findPos(obj)[1]+'px'; 1263 } 1264 function insertPhoto(size) { 1265 if(size == 'thumb') var src = fbThumb; 1266 else var src = fbFull; 1267 var html = 1268 '<a href="'+fbLink+'" class="fb-photo">' + 1269 '<img src="'+src+'" alt="'+fbCaption+'" />' + 1270 '</a> ' 1271 var win = window.opener ? window.opener : window.dialogArguments; 1272 if (!win) win = top; 1273 tinyMCE = win.tinyMCE; 1274 if (typeof tinyMCE != 'undefined' && tinyMCE.getInstanceById('content')) { 1275 tinyMCE.selectedInstance.getWin().focus(); 1276 tinyMCE.execCommand('mceInsertContent', false, html); 1277 } else win.edInsertContent(win.edCanvas, h); 1278 document.getElementById('fb-insert-popup').style.display = 'none'; 1279 } 1280 </script> 1281 <h3><?php echo $album['name'] ?> <a href="<?php echo $link ?>" style="font-size: 11px">« Back to Albums</a></small></h2> 1282 1283 <div id="fb-insert-popup"> 1284 Insert...<br /> 1285 <a href="#" onclick="insertPhoto('thumb'); return false;">Thumbnail</a><br /> 1286 <a href="#" onclick="insertPhoto('full'); return false;">Full</a><br /> 1287 <br /><a href="#" onclick="this.parentNode.style.display = 'none'; return false;">[close]</a> 1288 </div> 1289 1290 <ul id="fb-photos-tab"> 1291 <?php foreach($photos as $photo): ?> 1292 <li> 1293 <a href="#" onclick="insertPopup(this.parentNode, '<?php echo $photo['src'] ?>','<?php echo $photo['src_big'] ?>','<?php echo fb_get_photo_link($photo['pid']) ?>', '<?php echo addslashes($photo['caption']) ?>'); return false;"> 1294 <img src="<?php echo $photo['src']; ?>" /> 1295 </a> 1296 </li> 1297 <?php endforeach; ?> 1298 </ul> 1299 <?php 1300 else: 1301 $albums = fb_get_album(); 1302 ?> 1303 <h3>Select an Album</h3> 1304 <ul id="fb-manage-list"> 1305 <?php 1306 foreach($albums as $album): 1307 $thumb = fb_get_photo($album['cover_pid'], 'small'); 1308 ?> 1309 <li id="album_<?php echo $album['aid'] ?>" style="cursor: default"> 1310 <div class="thumb" style="background-image:url(<?php echo $thumb ?>);"></div> 1311 <div> 1312 <h3><a href="<?php echo $link ?>&aid=<?php echo $album['aid'] ?>"><?php echo $album['name'] ?></a></h3> 1313 <div class="description"> 1314 <small style="font-weight: normal"><?php echo $album['size'] ?> Photos</small><br /> 1315 </div> 1316 </div> 1317 <div style="clear: both"></div> 1318 </li> 1319 <?php endforeach; ?> 1320 </ul> 1321 <?php endif; ?> 1322 </form> 1323 <?php 1324 1324 } 1325 1325 1326 1326 if(get_bloginfo('version') >= 2.5) { 1327 add_filter('media_upload_tabs', 'fb_add_media_tab');1328 add_filter('media_upload_fotobook', 'media_upload_fotobook');1329 add_action('admin_head_media_upload_fotobook_tab', 'media_admin_css');1327 add_filter('media_upload_tabs', 'fb_add_media_tab'); 1328 add_filter('media_upload_fotobook', 'media_upload_fotobook'); 1329 add_action('admin_head_media_upload_fotobook_tab', 'media_admin_css'); 1330 1330 } else { 1331 add_filter('wp_upload_tabs', 'fb_add_upload_tab'); 1331 add_filter('wp_upload_tabs', 'fb_add_upload_tab'); 1332 1332 } 1333 1333 … … 1337 1337 1338 1338 function fb_widget_init() { 1339 if (!function_exists('register_sidebar_widget'))1340 return;1341 1342 register_sidebar_widget(array('Fotobook Photos', 'widgets'), 'fb_photos_widget');1343 register_widget_control(array('Fotobook Photos', 'widgets'), 'fb_photos_widget_control', 300, 150);1344 register_sidebar_widget(array('Fotobook Albums', 'widgets'), 'fb_albums_widget');1345 register_widget_control(array('Fotobook Albums', 'widgets'), 'fb_albums_widget_control', 300, 150);1339 if (!function_exists('register_sidebar_widget')) 1340 return; 1341 1342 register_sidebar_widget(array('Fotobook Photos', 'widgets'), 'fb_photos_widget'); 1343 register_widget_control(array('Fotobook Photos', 'widgets'), 'fb_photos_widget_control', 300, 150); 1344 register_sidebar_widget(array('Fotobook Albums', 'widgets'), 'fb_albums_widget'); 1345 register_widget_control(array('Fotobook Albums', 'widgets'), 'fb_albums_widget_control', 300, 150); 1346 1346 1347 1347 } 1348 1348 1349 1349 function fb_photos_widget($count = '4', $mode = 'random', $size = '80') { 1350 1351 // this is a widget1352 if(is_array($count)) {1353 extract($count);1354 1355 $options = get_option('fb_photos_widget');1356 if(is_array($options)) {1357 $title = $options['title'];1358 $count = $options['count'];1359 $size= $options['size'];1360 $mode= $options['mode'];1361 }1362 1363 echo $before_widget . $before_title . $title . $after_title;1364 }1365 1366 if($mode == 'recent') {1367 $photos = fb_get_recent_photos($count);1368 } else {1369 $photos = fb_get_random_photos($count);1370 }1371 1372 // if the thumbnail size is set larger than the size of1373 // the thumbnail, use the full size photo1374 if($size > 130) {1375 foreach($photos as $key=>$photo)1376 $photos[$key]['src'] = $photos[$key]['src_big'];1377 }1378 1379 if($photos) {1380 include(FB_PLUGIN_PATH.'styles/photos-widget.php');1381 } else {1382 echo '<p>There are no photos.</p>';1383 }1384 1385 echo $after_widget;1350 1351 // this is a widget 1352 if(is_array($count)) { 1353 extract($count); 1354 1355 $options = get_option('fb_photos_widget'); 1356 if(is_array($options)) { 1357 $title = $options['title']; 1358 $count = $options['count']; 1359 $size = $options['size']; 1360 $mode = $options['mode']; 1361 } 1362 1363 echo $before_widget . $before_title . $title . $after_title; 1364 } 1365 1366 if($mode == 'recent') { 1367 $photos = fb_get_recent_photos($count); 1368 } else { 1369 $photos = fb_get_random_photos($count); 1370 } 1371 1372 // if the thumbnail size is set larger than the size of 1373 // the thumbnail, use the full size photo 1374 if($size > 130) { 1375 foreach($photos as $key=>$photo) 1376 $photos[$key]['src'] = $photos[$key]['src_big']; 1377 } 1378 1379 if($photos) { 1380 include(FB_PLUGIN_PATH.'styles/photos-widget.php'); 1381 } else { 1382 echo '<p>There are no photos.</p>'; 1383 } 1384 1385 echo $after_widget; 1386 1386 } 1387 1387 1388 1388 function fb_photos_widget_control() { 1389 $options = get_option('fb_photos_widget');1390 if (!is_array($options) )1391 $options = array('title'=>'Random Photos', 'count'=>'4', 'style'=>'list','size'=>'80','mode'=>'random');1392 if ( $_POST['fb-photos-submit'] ) {1393 $options['title'] = strip_tags(stripslashes($_POST['fb-photos-title']));1394 $options['count'] = is_numeric($_POST['fb-photos-count']) ? $_POST['fb-photos-count'] : 4;1395 $options['style'] = $_POST['fb-photos-style'];1396 $options['mode'] = $_POST['fb-photos-mode'];1397 $options['size']= is_numeric($_POST['fb-photos-size']) ? $_POST['fb-photos-size'] : 60;1398 update_option('fb_photos_widget', $options);1399 }1400 $options['title'] = htmlspecialchars($options['title'], ENT_QUOTES);1401 1402 ?>1403 <p><label for="fb-title"><?php echo __('Title:'); ?>1404 <input style="width: 200px;" id="fb-photos-title" name="fb-photos-title" type="text" value="<?php echo $options['title'] ?>" />1405 </label></p>1406 <p><label for="fb-count"><?php echo __('Number of Pictures:'); ?>1407 <input style="width: 80px;" id="fb-photos-count" name="fb-photos-count" type="text" value="<?php echo $options['count'] ?>" />1408 </label></p>1409 <p><label for="fb-size"><?php echo __('Thumbnail Size:'); ?>1410 <input style="width: 80px;" id="fb-photos-size" name="fb-photos-size" type="text" value="<?php echo $options['size'] ?>" />1411 </label></p>1412 <p><?php echo __('Mode:'); ?>1413 <label><input type="radio" name="fb-photos-mode" value="recent" <?php echo $options['mode'] == 'recent' ? 'checked ' : '' ?>/> Recent Photos</label>1414 <label><input type="radio" name="fb-photos-mode" value="random" <?php echo $options['mode'] == 'random' ? 'checked ' : '' ?>/> Random Photos</label>1415 </p>1416 <input type="hidden" name="fb-photos-submit" value="1" />1417 <?php1389 $options = get_option('fb_photos_widget'); 1390 if (!is_array($options) ) 1391 $options = array('title'=>'Random Photos', 'count'=>'4', 'style'=>'list','size'=>'80','mode'=>'random'); 1392 if ( $_POST['fb-photos-submit'] ) { 1393 $options['title'] = strip_tags(stripslashes($_POST['fb-photos-title'])); 1394 $options['count'] = is_numeric($_POST['fb-photos-count']) ? $_POST['fb-photos-count'] : 4; 1395 $options['style'] = $_POST['fb-photos-style']; 1396 $options['mode'] = $_POST['fb-photos-mode']; 1397 $options['size'] = is_numeric($_POST['fb-photos-size']) ? $_POST['fb-photos-size'] : 60; 1398 update_option('fb_photos_widget', $options); 1399 } 1400 $options['title'] = htmlspecialchars($options['title'], ENT_QUOTES); 1401 1402 ?> 1403 <p><label for="fb-title"><?php echo __('Title:'); ?> 1404 <input style="width: 200px;" id="fb-photos-title" name="fb-photos-title" type="text" value="<?php echo $options['title'] ?>" /> 1405 </label></p> 1406 <p><label for="fb-count"><?php echo __('Number of Pictures:'); ?> 1407 <input style="width: 80px;" id="fb-photos-count" name="fb-photos-count" type="text" value="<?php echo $options['count'] ?>" /> 1408 </label></p> 1409 <p><label for="fb-size"><?php echo __('Thumbnail Size:'); ?> 1410 <input style="width: 80px;" id="fb-photos-size" name="fb-photos-size" type="text" value="<?php echo $options['size'] ?>" /> 1411 </label></p> 1412 <p><?php echo __('Mode:'); ?> 1413 <label><input type="radio" name="fb-photos-mode" value="recent" <?php echo $options['mode'] == 'recent' ? 'checked ' : '' ?>/> Recent Photos</label> 1414 <label><input type="radio" name="fb-photos-mode" value="random" <?php echo $options['mode'] == 'random' ? 'checked ' : '' ?>/> Random Photos</label> 1415 </p> 1416 <input type="hidden" name="fb-photos-submit" value="1" /> 1417 <?php 1418 1418 } 1419 1419 1420 1420 function fb_albums_widget($count = '4', $mode = 'recent') { 1421 global $wpdb;1422 1423 if(is_array($count)) {1424 extract($count);1425 1426 $options = get_option('fb_albums_widget');1427 if(is_array($options)) {1428 $title = $options['title'];1429 $mode= $options['mode'];1430 $count = $options['count'];1431 }1432 1433 echo $before_widget . $before_title . $title . $after_title;1434 }1435 1436 if($mode == 'recent') {1437 $albums = $wpdb->get_results('SELECT name, aid, page_id FROM '.FB_ALBUM_TABLE.' WHERE hidden = 0 ORDER BY modified DESC LIMIT '.$count, ARRAY_A);1438 } else {1439 $albums = $wpdb->get_results('SELECT name, aid, page_id FROM '.FB_ALBUM_TABLE.' WHERE hidden = 0 ORDER BY rand() LIMIT '.$count, ARRAY_A);1440 }1441 1442 if($albums) {1443 include(FB_PLUGIN_PATH.'styles/albums-widget.php');1444 } else {1445 echo '<p>There are no albums.</p>';1446 }1447 1448 echo $after_widget;1421 global $wpdb; 1422 1423 if(is_array($count)) { 1424 extract($count); 1425 1426 $options = get_option('fb_albums_widget'); 1427 if(is_array($options)) { 1428 $title = $options['title']; 1429 $mode = $options['mode']; 1430 $count = $options['count']; 1431 } 1432 1433 echo $before_widget . $before_title . $title . $after_title; 1434 } 1435 1436 if($mode == 'recent') { 1437 $albums = $wpdb->get_results('SELECT name, aid, page_id FROM '.FB_ALBUM_TABLE.' WHERE hidden = 0 ORDER BY modified DESC LIMIT '.$count, ARRAY_A); 1438 } else { 1439 $albums = $wpdb->get_results('SELECT name, aid, page_id FROM '.FB_ALBUM_TABLE.' WHERE hidden = 0 ORDER BY rand() LIMIT '.$count, ARRAY_A); 1440 } 1441 1442 if($albums) { 1443 include(FB_PLUGIN_PATH.'styles/albums-widget.php'); 1444 } else { 1445 echo '<p>There are no albums.</p>'; 1446 } 1447 1448 echo $after_widget; 1449 1449 } 1450 1450 1451 1451 function fb_albums_widget_control() { 1452 $options = get_option('fb_albums_widget');1453 if (!is_array($options) )1454 $options = array('title'=>'Recent Albums', 'mode'=>'recent', 'count'=>'4');1455 if ( $_POST['fb-albums-submit'] ) {1456 $options['title'] = strip_tags(stripslashes($_POST['fb-albums-title']));1457 $options['count'] = is_numeric($_POST['fb-albums-count']) ? $_POST['fb-albums-count'] : 4;1458 $options['mode'] = $_POST['fb-albums-mode'];1459 update_option('fb_albums_widget', $options);1460 }1461 $options['title'] = htmlspecialchars($options['title'], ENT_QUOTES);1462 1463 ?>1464 <p><label for="fb-title"><?php echo __('Title:'); ?>1465 <input style="width: 200px;" id="fb-albums-title" name="fb-albums-title" type="text" value="<?php echo $options['title'] ?>" />1466 </label></p>1467 <p><label for="fb-count"><?php echo __('Number of Albums:'); ?>1468 <input style="width: 80px;" id="fb-albums-count" name="fb-albums-count" type="text" value="<?php echo $options['count'] ?>" />1469 </label></p>1470 <p><?php echo __('Mode:'); ?>1471 <label><input type="radio" name="fb-albums-mode" value="recent" <?php echo $options['mode'] == 'recent' ? 'checked ' : '' ?>/> Recent Albums</label>1472 <label><input type="radio" name="fb-albums-mode" value="random" <?php echo $options['mode'] == 'random' ? 'checked ' : '' ?>/> Random Albums</label>1473 </p>1474 <input type="hidden" name="fb-albums-submit" value="1" />1475 <?php1452 $options = get_option('fb_albums_widget'); 1453 if (!is_array($options) ) 1454 $options = array('title'=>'Recent Albums', 'mode'=>'recent', 'count'=>'4'); 1455 if ( $_POST['fb-albums-submit'] ) { 1456 $options['title'] = strip_tags(stripslashes($_POST['fb-albums-title'])); 1457 $options['count'] = is_numeric($_POST['fb-albums-count']) ? $_POST['fb-albums-count'] : 4; 1458 $options['mode'] = $_POST['fb-albums-mode']; 1459 update_option('fb_albums_widget', $options); 1460 } 1461 $options['title'] = htmlspecialchars($options['title'], ENT_QUOTES); 1462 1463 ?> 1464 <p><label for="fb-title"><?php echo __('Title:'); ?> 1465 <input style="width: 200px;" id="fb-albums-title" name="fb-albums-title" type="text" value="<?php echo $options['title'] ?>" /> 1466 </label></p> 1467 <p><label for="fb-count"><?php echo __('Number of Albums:'); ?> 1468 <input style="width: 80px;" id="fb-albums-count" name="fb-albums-count" type="text" value="<?php echo $options['count'] ?>" /> 1469 </label></p> 1470 <p><?php echo __('Mode:'); ?> 1471 <label><input type="radio" name="fb-albums-mode" value="recent" <?php echo $options['mode'] == 'recent' ? 'checked ' : '' ?>/> Recent Albums</label> 1472 <label><input type="radio" name="fb-albums-mode" value="random" <?php echo $options['mode'] == 'random' ? 'checked ' : '' ?>/> Random Albums</label> 1473 </p> 1474 <input type="hidden" name="fb-albums-submit" value="1" /> 1475 <?php 1476 1476 } 1477 1477 … … 1480 1480 //------------------------// 1481 1481 1482 add_filter('wp_list_pages_excludes', 'fb_hidden_pages');1482 add_filter('wp_list_pages_excludes', 'fb_hidden_pages'); 1483 1483 add_action('activate_fotobook/fotobook.php', 'fb_initialize'); 1484 add_action('admin_menu', 'fb_add_pages');1485 add_filter('the_content', 'fb_display');1486 add_action('widgets_init', 'fb_widget_init');1487 add_action('wp_head', 'fb_head');1488 add_action('wp_ajax_fotobook', 'fb_ajax_handler');1484 add_action('admin_menu', 'fb_add_pages'); 1485 add_filter('the_content', 'fb_display'); 1486 add_action('widgets_init', 'fb_widget_init'); 1487 add_action('wp_head', 'fb_head'); 1488 add_action('wp_ajax_fotobook', 'fb_ajax_handler'); 1489 1489 1490 1490 //---------------------// … … 1493 1493 1494 1494 function array_slice_preserve_keys($array, $offset, $length = null) { 1495 // PHP >= 5.0.2 is able to do this itself1496 //if((int)str_replace('.', '', phpversion()) >= 502)1497 //return(array_slice($array, $offset, $length, true));1498 1499 // prepare input variables1500 $result = array();1501 $i = 0;1502 if($offset < 0)1503 $offset = count($array) + $offset;1504 if($length > 0)1505 $endOffset = $offset + $length;1506 else if($length < 0)1507 $endOffset = count($array) + $length;1508 else1509 $endOffset = count($array);1495 // PHP >= 5.0.2 is able to do this itself 1496 //if((int)str_replace('.', '', phpversion()) >= 502) 1497 //return(array_slice($array, $offset, $length, true)); 1498 1499 // prepare input variables 1500 $result = array(); 1501 $i = 0; 1502 if($offset < 0) 1503 $offset = count($array) + $offset; 1504 if($length > 0) 1505 $endOffset = $offset + $length; 1506 else if($length < 0) 1507 $endOffset = count($array) + $length; 1508 else 1509 $endOffset = count($array); 1510 1510 1511 // collect elements1512 foreach($array as $key=>$value)1513 {1514 if($i >= $offset && $i < $endOffset)1515 $result[$key] = $value;1516 $i++;1517 }1511 // collect elements 1512 foreach($array as $key=>$value) 1513 { 1514 if($i >= $offset && $i < $endOffset) 1515 $result[$key] = $value; 1516 $i++; 1517 } 1518 1518 1519 // return1520 return($result);1519 // return 1520 return($result); 1521 1521 } 1522 1522 1523 1523 if(!function_exists('file_put_contents')) { 1524 function file_put_contents($n,$d) {1525 $f=@fopen($n,"w");1526 if (!$f) {1527 return false;1528 } else {1529 fwrite($f,$d);1530 fclose($f);1531 return true;1532 }1533 }1524 function file_put_contents($n,$d) { 1525 $f=@fopen($n,"w"); 1526 if (!$f) { 1527 return false; 1528 } else { 1529 fwrite($f,$d); 1530 fclose($f); 1531 return true; 1532 } 1533 } 1534 1534 } 1535 1535 -
fotobook/trunk/js/admin.js
r167815 r167816 2 2 3 3 PeriodicalExecuter.prototype.registerCallback = function() { 4 this.intervalID = setInterval(this.onTimerEvent.bind(this), this.frequency * 1000);4 this.intervalID = setInterval(this.onTimerEvent.bind(this), this.frequency * 1000); 5 5 }; 6 6 7 7 PeriodicalExecuter.prototype.stop = function() { 8 clearInterval(this.intervalID);8 clearInterval(this.intervalID); 9 9 }; 10 10 11 jQuery(do cument).ready(function($) {11 jQuery(do cument).ready(function($) { 12 12 $('#grant-permissions').click(function() { 13 13 setTimeout(function() { … … 20 20 21 21 function toggleHidden(el, aid) { 22 var toggleHidden = new Ajax.Request('admin-ajax.php', { method: 'post', parameters: 'action=fotobook&hide='+aid });23 var row= el.parentNode.parentNode.parentNode.parentNode;24 if(el.innerHTML == 'Hide') {25 el.innerHTML = 'Show'; 26 Element.addClassName(row, 'disabled');27 } else {28 el.innerHTML = 'Hide';29 Element.removeClassName(row, 'disabled');30 }22 var toggleHidden = new Ajax.Request('admin-ajax.php', { method: 'post', parameters: 'action=fotobook&hide='+aid }); 23 var row = el.parentNode.parentNode.parentNode.parentNode; 24 if(el.innerHTML == 'Hide') { 25 el.innerHTML = 'Show'; 26 Element.addClassName(row, 'disabled'); 27 } else { 28 el.innerHTML = 'Hide'; 29 Element.removeClassName(row, 'disabled'); 30 } 31 31 } 32 32 33 33 function updateAlbumOrder() { 34 var order = Sortable.sequence('fb-manage-list');35 var updateAlbumOrder = new Ajax.Request('admin-ajax.php', {36 method: 'post',37 parameters: "action=fotobook&order=" + order38 });39 return true;34 var order = Sortable.sequence('fb-manage-list'); 35 var updateAlbumOrder = new Ajax.Request('admin-ajax.php', { 36 method: 'post', 37 parameters: "action=fotobook&order=" + order 38 }); 39 return true; 40 40 } 41 41 42 42 function getAlbumsList(message) { 43 var params = "action=fotobook&albums_list=true";44 if(message != '') params += "&message="+escape(message);45 var getAlbumsList = new Ajax.Updater('fb-manage', 'admin-ajax.php', {46 method: 'post',47 parameters: params,48 evalScripts: true49 });43 var params = "action=fotobook&albums_list=true"; 44 if(message != '') params += "&message="+escape(message); 45 var getAlbumsList = new Ajax.Updater('fb-manage', 'admin-ajax.php', { 46 method: 'post', 47 parameters: params, 48 evalScripts: true 49 }); 50 50 } 51 51 52 52 function getAlbums() { 53 setProgress('update-progress', 0);54 Effect.Appear('progress-container');55 Element.addClassName('fb-manage-list', 'disabled');56 var getAlbums = new Ajax.Request('admin-ajax.php', {57 method: 'post',58 parameters: "action=fotobook&update=true",59 onComplete: getAlbumsComplete60 });61 var pe = new PeriodicalExecuter(updateProgressBar, 3);62 function getAlbumsComplete(request) {63 pe.stop();64 setProgress('update-progress', 100);65 var response = request.responseText;66 getAlbumsList(response);67 Effect.Fade('progress-container');68 }53 setProgress('update-progress', 0); 54 Effect.Appear('progress-container'); 55 Element.addClassName('fb-manage-list', 'disabled'); 56 var getAlbums = new Ajax.Request('admin-ajax.php', { 57 method: 'post', 58 parameters: "action=fotobook&update=true", 59 onComplete: getAlbumsComplete 60 }); 61 var pe = new PeriodicalExecuter(updateProgressBar, 3); 62 function getAlbumsComplete(request) { 63 pe.stop(); 64 setProgress('update-progress', 100); 65 var response = request.responseText; 66 getAlbumsList(response); 67 Effect.Fade('progress-container'); 68 } 69 69 } 70 70 71 71 function updateProgressBar() { 72 var getProgress = new Ajax.Request('admin-ajax.php', {73 method: 'post',74 parameters: "action=fotobook&progress=true",75 onComplete: progressResponse76 });77 function progressResponse(request) {78 var progress = request.responseText;79 setProgress('update-progress', progress);80 }72 var getProgress = new Ajax.Request('admin-ajax.php', { 73 method: 'post', 74 parameters: "action=fotobook&progress=true", 75 onComplete: progressResponse 76 }); 77 function progressResponse(request) { 78 var progress = request.responseText; 79 setProgress('update-progress', progress); 80 } 81 81 } 82 82 83 83 function resetOrder() { 84 var resetOrder = new Ajax.Request('admin-ajax.php', {85 method: 'post',86 parameters: "action=fotobook&reset_order=true",87 onComplete: function(request) {88 getAlbumsList(request.responseText);89 }90 });84 var resetOrder = new Ajax.Request('admin-ajax.php', { 85 method: 'post', 86 parameters: "action=fotobook&reset_order=true", 87 onComplete: function(request) { 88 getAlbumsList(request.responseText); 89 } 90 }); 91 91 } 92 92 93 93 function removeAll() { 94 var removeAll = new Ajax.Request('admin-ajax.php', {95 method: 'post',96 parameters: "action=fotobook&remove_all=true",97 onComplete: function(request) {98 getAlbumsList(request.responseText);99 }100 });94 var removeAll = new Ajax.Request('admin-ajax.php', { 95 method: 'post', 96 parameters: "action=fotobook&remove_all=true", 97 onComplete: function(request) { 98 getAlbumsList(request.responseText); 99 } 100 }); 101 101 } 102 102 103 103 function changeStylesheet(obj) { 104 var styles = $('fb-stylesheets').getElementsByTagName('textarea');105 for(i = 0; i < styles.length; i++) {106 Element.hide(styles[i].parentNode);107 }108 Element.show(obj.value+'-stylesheet');104 var styles = $('fb-stylesheets').getElementsByTagName('textarea'); 105 for(i = 0; i < styles.length; i++) { 106 Element.hide(styles[i].parentNode); 107 } 108 Element.show(obj.value+'-stylesheet'); 109 109 } -
fotobook/trunk/manage-fotobook.php
r167260 r167816 14 14 </style> 15 15 <?php if(!$facebook->link_active()): ?> 16 <div id="message" class="error fade"><p>There is no Facebook account linked to this plugin. Change that <a href="<?php echo FB_OPTIONS_URL ?>">here</a>.</p></div>16 <div id="message" class="error fade"><p>There is no Facebook account linked to this plugin. Change that <a href="<?php echo FB_OPTIONS_URL ?>">here</a>.</p></div> 17 17 <?php endif; ?> 18 18 … … 23 23 <div class="wrap"> 24 24 25 <div id="fb-panel">26 <?php fb_info_box() ?>27 <h2 style="clear: none"><?php _e('Fotobook › Manage'); ?> <span><a href="<?php echo FB_OPTIONS_URL ?>">Change Settings »</a></span></h2>28 <p><?php _e('This is where you can import and manage your Facebook albums.You can drag the albums to change the order.'); ?></p>29 <?php if(!fb_albums_page_is_set()): ?>30 <p><em>You must select a page for the photo gallery in the <a href="<?php echo FB_OPTIONS_URL ?>">Fotobook Options</a> panel before you can import albums.</em></p>31 <?php else: ?>32 <?php if($facebook->link_active()): ?>33 <div class="nav">34 <input type="button" class="button-secondary" name="Submit" onclick="getAlbums(); return false;" value="Get Albums" style="width: 100px" />35 <input type="button" class="button-secondary" name="Submit" onclick="resetOrder(); return false;" value="Order By Date" />36 <input type="button" class="button-secondary" name="Submit" onclick="removeAll(); return false;" value="Remove All" /> 37 <span id="progress-container" style="display: none"> <script>displayProgress('update-progress',0);</script></span>38 </div>39 <?php endif; ?>40 41 <div id="fb-manage">42 <p>Loading...</p>43 <script language="javascript">getAlbumsList(false);</script>44 </div>45 46 <?php endif; // condition checking if a gallery page is selected?>47 </div>25 <div id="fb-panel"> 26 <?php fb_info_box() ?> 27 <h2 style="clear: none"><?php _e('Fotobook › Manage'); ?> <span><a href="<?php echo FB_OPTIONS_URL ?>">Change Settings »</a></span></h2> 28 <p><?php _e('This is where you can import and manage your Facebook albums. You can drag the albums to change the order.'); ?></p> 29 <?php if(!fb_albums_page_is_set()): ?> 30 <p><em>You must select a page for the photo gallery in the <a href="<?php echo FB_OPTIONS_URL ?>">Fotobook Options</a> panel before you can import albums.</em></p> 31 <?php else: ?> 32 <?php if($facebook->link_active()): ?> 33 <div class="nav"> 34 <input type="button" class="button-secondary" name="Submit" onclick="getAlbums(); return false;" value="Get Albums" style="width: 100px" /> 35 <input type="button" class="button-secondary" name="Submit" onclick="resetOrder(); return false;" value="Order By Date" /> 36 <input type="button" class="button-secondary" name="Submit" onclick="removeAll(); return false;" value="Remove All" /> 37 <span id="progress-container" style="display: none"> <script>displayProgress('update-progress',0);</script></span> 38 </div> 39 <?php endif; ?> 40 41 <div id="fb-manage"> 42 <p>Loading...</p> 43 <script language="javascript">getAlbumsList(false);</script> 44 </div> 45 46 <?php endif; // condition checking if a gallery page is selected ?> 47 </div> 48 48 </div> -
fotobook/trunk/options-fotobook.php
r167815 r167816 10 10 // authorize session 11 11 if(isset($_POST['activate-facebook'])) { 12 $facebook->get_auth_session($_POST['activate-facebook']);12 $facebook->get_auth_session($_POST['activate-facebook']); 13 13 } 14 14 15 15 // remove the user 16 16 if(isset($_GET['deactivate-facebook']) && isset($facebook->sessions[$_GET['deactivate-facebook']])) { 17 $facebook->remove_user($_GET['deactivate-facebook']);17 $facebook->remove_user($_GET['deactivate-facebook']); 18 18 } 19 19 … … 25 25 // update options if form is submitted 26 26 if (isset($_POST['submit'])) { 27 fb_options_update_albums_page($_POST['fb_albums_page']); 28 update_option('fb_number_rows', $_POST['fb_number_rows']);29 update_option('fb_style', $_POST['fb_style']);30 if($_POST['fb_number_cols'] != 0) {31 update_option('fb_number_cols', $_POST['fb_number_cols']);32 }33 if(is_numeric($_POST['fb_embedded_width'])) {34 update_option('fb_embedded_width', $_POST['fb_embedded_width']);35 }36 update_option('fb_thumb_size', $_POST['fb_thumb_size']);37 update_option('fb_albums_per_page', $_POST['fb_albums_per_page']);38 update_option('fb_hide_pages', isset($_POST['fb_hide_pages']) ? 1 : 0);39 if(isset($_POST['fb_album_cmts'])) {40 fb_options_toggle_comments(true);41 update_option('fb_album_cmts', 1);42 } else {43 fb_options_toggle_comments(false);44 update_option('fb_album_cmts', 0);45 }46 foreach($styles as $style) {47 $stylesheet = FB_PLUGIN_PATH.'styles/'.$style.'/style.css';48 if(is_writable($stylesheet)) {49 file_put_contents($stylesheet, $_POST[$style.'_stylesheet']);50 } 51 }52 $sidebar_stylesheet = FB_PLUGIN_PATH.'styles/sidebar-style.css';53 if(is_writable($sidebar_stylesheet)) {54 file_put_contents($sidebar_stylesheet, $_POST['sidebar_stylesheet']);55 }27 fb_options_update_albums_page($_POST['fb_albums_page']); 28 update_option('fb_number_rows', $_POST['fb_number_rows']); 29 update_option('fb_style', $_POST['fb_style']); 30 if($_POST['fb_number_cols'] != 0) { 31 update_option('fb_number_cols', $_POST['fb_number_cols']); 32 } 33 if(is_numeric($_POST['fb_embedded_width'])) { 34 update_option('fb_embedded_width', $_POST['fb_embedded_width']); 35 } 36 update_option('fb_thumb_size', $_POST['fb_thumb_size']); 37 update_option('fb_albums_per_page', $_POST['fb_albums_per_page']); 38 update_option('fb_hide_pages', isset($_POST['fb_hide_pages']) ? 1 : 0); 39 if(isset($_POST['fb_album_cmts'])) { 40 fb_options_toggle_comments(true); 41 update_option('fb_album_cmts', 1); 42 } else { 43 fb_options_toggle_comments(false); 44 update_option('fb_album_cmts', 0); 45 } 46 foreach($styles as $style) { 47 $stylesheet = FB_PLUGIN_PATH.'styles/'.$style.'/style.css'; 48 if(is_writable($stylesheet)) { 49 file_put_contents($stylesheet, $_POST[$style.'_stylesheet']); 50 } 51 } 52 $sidebar_stylesheet = FB_PLUGIN_PATH.'styles/sidebar-style.css'; 53 if(is_writable($sidebar_stylesheet)) { 54 file_put_contents($sidebar_stylesheet, $_POST['sidebar_stylesheet']); 55 } 56 56 } 57 57 58 58 // add a photo album page if there is none 59 59 if(get_option('fb_albums_page') == 0) { 60 $page = array(61 'post_author'=> 1,62 'post_content'=>'',63 'post_title'=>'Photos',64 'post_name'=>'photos',65 'comment_status' =>1,66 'post_parent'=>067 );68 // add a photo album page69 if(get_bloginfo('version') >= 2.1) { 70 $page['post_status'] = 'publish';71 $page['post_type']= 'page';72 } else {73 $page['post_status'] = 'static';74 }75 $page_id = wp_insert_post($page);76 update_option('fb_albums_page', $page_id);60 $page = array( 61 'post_author' => 1, 62 'post_content' =>'', 63 'post_title' =>'Photos', 64 'post_name' =>'photos', 65 'comment_status' =>1, 66 'post_parent' =>0 67 ); 68 // add a photo album page 69 if(get_bloginfo('version') >= 2.1) { 70 $page['post_status'] = 'publish'; 71 $page['post_type'] = 'page'; 72 } else { 73 $page['post_status'] = 'static'; 74 } 75 $page_id = wp_insert_post($page); 76 update_option('fb_albums_page', $page_id); 77 77 } 78 78 79 79 // get options to fill in input fields 80 $fb_session = get_option('fb_facebook_session');81 $fb_albums_page = get_option('fb_albums_page');82 $fb_number_rows = get_option('fb_number_rows');83 $fb_number_cols = get_option('fb_number_cols');84 $fb_album_cmts = get_option('fb_album_cmts');85 $fb_thumb_size = get_option('fb_thumb_size');80 $fb_session = get_option('fb_facebook_session'); 81 $fb_albums_page = get_option('fb_albums_page'); 82 $fb_number_rows = get_option('fb_number_rows'); 83 $fb_number_cols = get_option('fb_number_cols'); 84 $fb_album_cmts = get_option('fb_album_cmts'); 85 $fb_thumb_size = get_option('fb_thumb_size'); 86 86 $fb_albums_per_page = get_option('fb_albums_per_page'); 87 $fb_style = get_option('fb_style');88 $fb_embedded_width = get_option('fb_embedded_width');89 $fb_hide_pages = get_option('fb_hide_pages');90 91 ?> 87 $fb_style = get_option('fb_style'); 88 $fb_embedded_width = get_option('fb_embedded_width'); 89 $fb_hide_pages = get_option('fb_hide_pages'); 90 91 ?> 92 92 93 93 <style type="text/css"> … … 100 100 101 101 <div class="wrap"> 102 <div id="fb-panel">103 <?php fb_info_box() ?>104 <h2 style="clear: none"><?php _e('Fotobook › Settings') ?> <span><a href="<?php echo FB_MANAGE_URL ?>">Manage Albums »</a></span></h2>105 <p>This plugin links to your Facebook account and imports all of your albums into a page on your blog. To get106 started you need to give permission to the plugin to access your Facebook account and then import107 your albums on the management page.</p>108 <h3>Facebook</h3>109 <p>To use this plugin, you must link it to your Facebook account.</p>110 <table class="accounts">111 <tr>112 <td valign="top">113 <table>114 <tr>115 <th colspan="2" style="text-align: center"><h3>Add an Account</h3></th>116 </tr> 117 <tr>118 <td colspan="2">119 <?php if($facebook->token): ?>120 <p><a id="grant-permissions" href="http://www.facebook.com/login.php?api_key=<?php echo FB_API_KEY ?>&v=1.0&auth_token=<?php echo $facebook->token ?>&popup=1&skipcookie=1&KeepThis=true&TB_iframe=true&height=400&width=600" class="button-secondary thickbox">Authorize Account</a></p>121 <form method="post" id="apply-permissions" action="<?php echo FB_OPTIONS_URL ?>" style="display: none">122 <input type="hidden" name="activate-facebook" value="<?php echo $facebook->token ?>" />123 <input type="submit" class="button-secondary" value="Apply Permissions >" />124 </form>125 <?php else: ?>126 Unable to get authorization token.127 <?php endif ?>128 </td>129 </tr>130 </table>131 </td>132 <td valign="top">133 <table>134 <tr>135 <th colspan="2" style="text-align: center"><h3>Current Accounts</h3></th>136 </tr>137 <?php138 if($facebook->link_active()):139 foreach($facebook->sessions as $key=>$value):140 ?>141 <tr>142 <td class="username">143 <img src="http://www.facebook.com/favicon.ico" align="absmiddle">144 <a href="http://www.facebook.com/profile.php?id=<?php echo $facebook->sessions[$key]['uid'] ?>" target="_blank"><?php echo $facebook->sessions[$key]['name']; ?></a>145 </td>146 <td>147 <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="get">148 <input type="hidden" name="deactivate-facebook" value="<?php echo $key ?>">149 <input type="hidden" name="page" value="<?php echo $_GET['page'] ?>">150 <input type="submit" class="button-secondary" value="Remove" onclick="return confirm('Removing an account also removes all of the photos associated with the account.Would you like to continue?')">151 </form>152 </td>153 </tr>154 <?php endforeach; ?>155 <?php else: ?>156 <tr><td colspan="2">There are currently no active Facebook accounts.</td></tr>157 <?php endif; ?> 158 </table>159 <?php if($facebook->link_active()): ?>160 <p><small>This plugin has been given access to data from your Facebook account.You can revoke this access at any time by clicking remove above or by changing your <a href="http://www.facebook.com/privacy.php?view=platform&tab=ext" target="_blank">privacy</a> settings.</small></p>161 <?php endif; ?>162 </td>163 </tr>164 </table>165 166 <form method="post" action="<?php echo $this_page ?>&updated=true">167 <h3><?php _e('General') ?></h3>168 <table class="form-table">169 <tr>170 <th scope="row"><?php _e('Albums Page') ?></th>171 <td>172 <select name="fb_albums_page">173 <?php if(!fb_albums_page_is_set()): ?>174 <option value="0" selected>Please select...</option>175 <?php endif; ?>176 <?php fb_parent_dropdown($fb_albums_page); ?>177 </select><br />178 <small>Select the page you want to use to display the photo albums.</small>179 </td>180 </tr>181 <tr>182 <th scope="row"><?php _e('Albums Per Page') ?></th>183 <td>184 <input name="fb_albums_per_page" type="text" value="<?php echo $fb_albums_per_page; ?>" size="3" />185 <small><?php _e('Number of albums to display on each page of the main gallery. Set to \'0\' to show all.') ?></small>186 </td>187 </tr>188 <tr>189 <th scope="row"><?php _e('Number of Rows') ?></th>190 <td>191 <input name="fb_number_rows" type="text" value="<?php echo $fb_number_rows; ?>" size="3" />192 <small><?php _e('Set to \'0\' to display all.') ?></small>193 </td>194 </tr>195 <tr>196 <th scope="row"><?php _e('Number of Columns') ?></th>197 <td>198 <input name="fb_number_cols" type="text" value="<?php echo $fb_number_cols; ?>" size="3" />199 <small><?php _e('The number of columns of pictures.') ?></small>200 </td>201 </tr>202 <tr>203 <th scope="row"><?php _e('Display Style') ?></th>204 <td>205 <select name="fb_style">206 <?php foreach($styles as $style):207 $selected = $style == $fb_style ? ' selected' : null; ?>208 <option value="<?php echo $style ?>"<?php echo $selected; ?>><?php echo $style ?></option>209 <?php endforeach; ?>210 </select>211 <small><?php _e('Select the style you want to use to display the albums.') ?></small>212 </td>213 </tr>214 <tr>215 <th scope="row"><?php _e('Embedded Width') ?></th>216 <td>217 <input name="fb_embedded_width" type="text" value="<?php echo $fb_embedded_width; ?>" size="3" />px218 <small><?php _e('Restrain the width of the embedded photo if it is too wide for your theme.Set to \'0\' to display the full size.') ?></small>219 </td>220 </tr>221 <tr>222 <th scope="row"><?php _e('Max Thumbnail Size') ?></th>223 <td>224 <input name="fb_thumb_size" type="text" value="<?php echo $fb_thumb_size; ?>" size="3" />px225 <small><?php _e('The maximum size of the thumbnail. The default is 130px.') ?></small>226 </td>227 </tr>228 <tr>229 <th scope="row"><?php _e('Album Commenting') ?></th>230 <td>231 <label><input name="fb_album_cmts" type="checkbox" value="1" <?php if($fb_album_cmts) echo 'checked'; ?> />232 <small><?php _e('Allow commenting on individual albums.This must be supported by your theme.') ?></small></label>233 </td>234 </tr>235 <tr>236 <th scope="row"><?php _e('Hide Album Pages') ?></th>237 <td>238 <label><input name="fb_hide_pages" type="checkbox" value="1" <?php if($fb_hide_pages) echo 'checked'; ?> />239 <small><?php _e('Exclude album pages from being displayed in places where pages are listed.') ?></small></label>240 </td>241 </tr>242 <tr>243 <th scope="row"><?php _e('Cron URL') ?></th>244 <td>To setup automatic updates of your albums, create a cron job that regularly loads the following URL.If you are unsure how to setup a cron job, <a href="http://www.google.com/search?q=cron">Google</a> is your friend.<br /> <small><?php echo fb_cron_url() ?></small></td>245 </tr>246 </table>247 248 <h3><?php _e('Stylesheets') ?></h3>249 <table class="form-table">250 <tr><td>251 <div id="fb-stylesheets" class="editform" style="width: 98%">252 <p>Select:253 <select onchange="changeStylesheet(this);">254 <?php255 $styles[] = 'sidebar';256 foreach($styles as $style):257 $selected = $style == $fb_style ? ' selected' : null;258 ?>259 <option value="<?php echo $style ?>"<?php echo $selected; ?>><?php echo $style ?></option>260 <?php endforeach; ?>261 </select>262 </p>263 <?php264 foreach($styles as $style):265 $stylesheet = FB_PLUGIN_PATH.'styles/'.$style.'/style.css';266 if($style == 'sidebar') $stylesheet = FB_PLUGIN_PATH.'styles/sidebar-style.css';267 ?>268 <div id="<?php echo $style ?>-stylesheet"<?php echo $style != $fb_style ? ' style="display: none"' : '' ?>>269 <textarea name="<?php echo $style ?>_stylesheet" style="width: 100%; height: 250px"<?php echo is_writable($stylesheet) ? '' : ' disabled="true"' ?>><?php echo file_get_contents($stylesheet) ?></textarea>270 <?php echo is_writable($stylesheet) ? '' : '<em>This file is not writable.</em>' ?>271 </div>272 <?php endforeach; ?>273 </div>274 </td></tr>275 </table>276 277 <p><strong><a href="#" onclick="$('fb-debug-info').toggle(); return false;">View Debug Info »</a></strong></p>278 <table class="form-table" id="fb-debug-info" style="display: none">279 <tr>280 <th>Fotobook Version</th>281 <td><?php echo FB_VERSION ?></td>282 </tr>283 <tr>284 <th>WordPress Version</th>285 <td><?php bloginfo('version') ?></td>286 </tr>287 <tr>288 <th>PHP Version</th>289 <td><?php echo PHP_VERSION ?></td>290 </tr>291 <tr>292 <th>Allow URL fopen</th>293 <td><?php echo ini_get('allow_url_fopen') ? 'Enabled' : 'Disabled' ?></td>294 </tr>295 <tr>296 <th>Curl</th>297 <td><?php echo extension_loaded('curl') ? 'Installed' : 'Not Installed' ?></td>298 </tr>299 <tr>300 <th>Safe Mode</th>301 <td><?php echo ini_get('safe_mode') ? 'Enabled' : 'Disabled' ?></td>302 </tr>303 <tr>304 <th>Max Execution Time</th>305 <td><?php echo ini_get('max_execution_time') ?> seconds</td>306 </tr>307 </table>308 309 <p class="submit">310 <input type="submit" name="submit" value="<?php _e('Update Options') ?> »" />311 </p>312 </form>313 </div>102 <div id="fb-panel"> 103 <?php fb_info_box() ?> 104 <h2 style="clear: none"><?php _e('Fotobook › Settings') ?> <span><a href="<?php echo FB_MANAGE_URL ?>">Manage Albums »</a></span></h2> 105 <p>This plugin links to your Facebook account and imports all of your albums into a page on your blog. To get 106 started you need to give permission to the plugin to access your Facebook account and then import 107 your albums on the management page.</p> 108 <h3>Facebook</h3> 109 <p>To use this plugin, you must link it to your Facebook account.</p> 110 <table class="accounts"> 111 <tr> 112 <td valign="top"> 113 <table> 114 <tr> 115 <th colspan="2" style="text-align: center"><h3>Add an Account</h3></th> 116 </tr> 117 <tr> 118 <td colspan="2"> 119 <?php if($facebook->token): ?> 120 <p><a id="grant-permissions" href="http://www.facebook.com/login.php?api_key=<?php echo FB_API_KEY ?>&v=1.0&auth_token=<?php echo $facebook->token ?>&popup=1&skipcookie=1&KeepThis=true&TB_iframe=true&height=400&width=600" class="button-secondary thickbox">Authorize Account</a></p> 121 <form method="post" id="apply-permissions" action="<?php echo FB_OPTIONS_URL ?>" style="display: none"> 122 <input type="hidden" name="activate-facebook" value="<?php echo $facebook->token ?>" /> 123 <input type="submit" class="button-secondary" value="Apply Permissions >" /> 124 </form> 125 <?php else: ?> 126 Unable to get authorization token. 127 <?php endif ?> 128 </td> 129 </tr> 130 </table> 131 </td> 132 <td valign="top"> 133 <table> 134 <tr> 135 <th colspan="2" style="text-align: center"><h3>Current Accounts</h3></th> 136 </tr> 137 <?php 138 if($facebook->link_active()): 139 foreach($facebook->sessions as $key=>$value): 140 ?> 141 <tr> 142 <td class="username"> 143 <img src="http://www.facebook.com/favicon.ico" align="absmiddle"> 144 <a href="http://www.facebook.com/profile.php?id=<?php echo $facebook->sessions[$key]['uid'] ?>" target="_blank"><?php echo $facebook->sessions[$key]['name']; ?></a> 145 </td> 146 <td> 147 <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="get"> 148 <input type="hidden" name="deactivate-facebook" value="<?php echo $key ?>"> 149 <input type="hidden" name="page" value="<?php echo $_GET['page'] ?>"> 150 <input type="submit" class="button-secondary" value="Remove" onclick="return confirm('Removing an account also removes all of the photos associated with the account. Would you like to continue?')"> 151 </form> 152 </td> 153 </tr> 154 <?php endforeach; ?> 155 <?php else: ?> 156 <tr><td colspan="2">There are currently no active Facebook accounts.</td></tr> 157 <?php endif; ?> 158 </table> 159 <?php if($facebook->link_active()): ?> 160 <p><small>This plugin has been given access to data from your Facebook account. You can revoke this access at any time by clicking remove above or by changing your <a href="http://www.facebook.com/privacy.php?view=platform&tab=ext" target="_blank">privacy</a> settings.</small></p> 161 <?php endif; ?> 162 </td> 163 </tr> 164 </table> 165 166 <form method="post" action="<?php echo $this_page ?>&updated=true"> 167 <h3><?php _e('General') ?></h3> 168 <table class="form-table"> 169 <tr> 170 <th scope="row"><?php _e('Albums Page') ?></th> 171 <td> 172 <select name="fb_albums_page"> 173 <?php if(!fb_albums_page_is_set()): ?> 174 <option value="0" selected>Please select...</option> 175 <?php endif; ?> 176 <?php fb_parent_dropdown($fb_albums_page); ?> 177 </select><br /> 178 <small>Select the page you want to use to display the photo albums.</small> 179 </td> 180 </tr> 181 <tr> 182 <th scope="row"><?php _e('Albums Per Page') ?></th> 183 <td> 184 <input name="fb_albums_per_page" type="text" value="<?php echo $fb_albums_per_page; ?>" size="3" /> 185 <small><?php _e('Number of albums to display on each page of the main gallery. Set to \'0\' to show all.') ?></small> 186 </td> 187 </tr> 188 <tr> 189 <th scope="row"><?php _e('Number of Rows') ?></th> 190 <td> 191 <input name="fb_number_rows" type="text" value="<?php echo $fb_number_rows; ?>" size="3" /> 192 <small><?php _e('Set to \'0\' to display all.') ?></small> 193 </td> 194 </tr> 195 <tr> 196 <th scope="row"><?php _e('Number of Columns') ?></th> 197 <td> 198 <input name="fb_number_cols" type="text" value="<?php echo $fb_number_cols; ?>" size="3" /> 199 <small><?php _e('The number of columns of pictures.') ?></small> 200 </td> 201 </tr> 202 <tr> 203 <th scope="row"><?php _e('Display Style') ?></th> 204 <td> 205 <select name="fb_style"> 206 <?php foreach($styles as $style): 207 $selected = $style == $fb_style ? ' selected' : null; ?> 208 <option value="<?php echo $style ?>"<?php echo $selected; ?>><?php echo $style ?></option> 209 <?php endforeach; ?> 210 </select> 211 <small><?php _e('Select the style you want to use to display the albums.') ?></small> 212 </td> 213 </tr> 214 <tr> 215 <th scope="row"><?php _e('Embedded Width') ?></th> 216 <td> 217 <input name="fb_embedded_width" type="text" value="<?php echo $fb_embedded_width; ?>" size="3" />px 218 <small><?php _e('Restrain the width of the embedded photo if it is too wide for your theme. Set to \'0\' to display the full size.') ?></small> 219 </td> 220 </tr> 221 <tr> 222 <th scope="row"><?php _e('Max Thumbnail Size') ?></th> 223 <td> 224 <input name="fb_thumb_size" type="text" value="<?php echo $fb_thumb_size; ?>" size="3" />px 225 <small><?php _e('The maximum size of the thumbnail. The default is 130px.') ?></small> 226 </td> 227 </tr> 228 <tr> 229 <th scope="row"><?php _e('Album Commenting') ?></th> 230 <td> 231 <label><input name="fb_album_cmts" type="checkbox" value="1" <?php if($fb_album_cmts) echo 'checked'; ?> /> 232 <small><?php _e('Allow commenting on individual albums. This must be supported by your theme.') ?></small></label> 233 </td> 234 </tr> 235 <tr> 236 <th scope="row"><?php _e('Hide Album Pages') ?></th> 237 <td> 238 <label><input name="fb_hide_pages" type="checkbox" value="1" <?php if($fb_hide_pages) echo 'checked'; ?> /> 239 <small><?php _e('Exclude album pages from being displayed in places where pages are listed.') ?></small></label> 240 </td> 241 </tr> 242 <tr> 243 <th scope="row"><?php _e('Cron URL') ?></th> 244 <td>To setup automatic updates of your albums, create a cron job that regularly loads the following URL. If you are unsure how to setup a cron job, <a href="http://www.google.com/search?q=cron">Google</a> is your friend.<br /> <small><?php echo fb_cron_url() ?></small></td> 245 </tr> 246 </table> 247 248 <h3><?php _e('Stylesheets') ?></h3> 249 <table class="form-table"> 250 <tr><td> 251 <div id="fb-stylesheets" class="editform" style="width: 98%"> 252 <p>Select: 253 <select onchange="changeStylesheet(this);"> 254 <?php 255 $styles[] = 'sidebar'; 256 foreach($styles as $style): 257 $selected = $style == $fb_style ? ' selected' : null; 258 ?> 259 <option value="<?php echo $style ?>"<?php echo $selected; ?>><?php echo $style ?></option> 260 <?php endforeach; ?> 261 </select> 262 </p> 263 <?php 264 foreach($styles as $style): 265 $stylesheet = FB_PLUGIN_PATH.'styles/'.$style.'/style.css'; 266 if($style == 'sidebar') $stylesheet = FB_PLUGIN_PATH.'styles/sidebar-style.css'; 267 ?> 268 <div id="<?php echo $style ?>-stylesheet"<?php echo $style != $fb_style ? ' style="display: none"' : '' ?>> 269 <textarea name="<?php echo $style ?>_stylesheet" style="width: 100%; height: 250px"<?php echo is_writable($stylesheet) ? '' : ' disabled="true"' ?>><?php echo file_get_contents($stylesheet) ?></textarea> 270 <?php echo is_writable($stylesheet) ? '' : '<em>This file is not writable.</em>' ?> 271 </div> 272 <?php endforeach; ?> 273 </div> 274 </td></tr> 275 </table> 276 277 <p><strong><a href="#" onclick="$('fb-debug-info').toggle(); return false;">View Debug Info »</a></strong></p> 278 <table class="form-table" id="fb-debug-info" style="display: none"> 279 <tr> 280 <th>Fotobook Version</th> 281 <td><?php echo FB_VERSION ?></td> 282 </tr> 283 <tr> 284 <th>WordPress Version</th> 285 <td><?php bloginfo('version') ?></td> 286 </tr> 287 <tr> 288 <th>PHP Version</th> 289 <td><?php echo PHP_VERSION ?></td> 290 </tr> 291 <tr> 292 <th>Allow URL fopen</th> 293 <td><?php echo ini_get('allow_url_fopen') ? 'Enabled' : 'Disabled' ?></td> 294 </tr> 295 <tr> 296 <th>Curl</th> 297 <td><?php echo extension_loaded('curl') ? 'Installed' : 'Not Installed' ?></td> 298 </tr> 299 <tr> 300 <th>Safe Mode</th> 301 <td><?php echo ini_get('safe_mode') ? 'Enabled' : 'Disabled' ?></td> 302 </tr> 303 <tr> 304 <th>Max Execution Time</th> 305 <td><?php echo ini_get('max_execution_time') ?> seconds</td> 306 </tr> 307 </table> 308 309 <p class="submit"> 310 <input type="submit" name="submit" value="<?php _e('Update Options') ?> »" /> 311 </p> 312 </form> 313 </div> 314 314 </div>
Note: See TracChangeset
for help on using the changeset viewer.