/** * getAjaxFacebookPhotos * * Will print a list of photos from facebook. * * @return null */ function getAjaxFacebookPhotos() { $config = getFacebookConfigData(); $accessToken = getUserFacebookAccessToken($this->fcmsUser->id); $facebook = new Facebook(array('appId' => $config['fb_app_id'], 'secret' => $config['fb_secret'])); $facebook->setAccessToken($accessToken); $albumId = (int) $_POST['albumId']; $photos = ''; $i = 1; $_SESSION['facebook_photos'] = array(); try { $fbPhotos = $facebook->api("/{$albumId}/photos"); foreach ($fbPhotos['data'] as $photo) { $w = $photo['width']; $h = $photo['height']; $width = '100%;'; $height = 'auto;'; if ($w > $h) { $width = 'auto;'; $height = '100%;'; } $sourceId = $photo['id']; $thumbnail = $photo['picture']; $_SESSION['facebook_photos'][$sourceId] = array('thumbnail' => $thumbnail, 'width' => $width, 'height' => $height); $photos .= '<li>'; $photos .= '<label for="facebook' . $i . '">'; $photos .= '<img src="' . $thumbnail . '" style="width:' . $width . ' height:' . $height . '"/>'; $photos .= '<span style="display:none"></span>'; $photos .= '</label>'; $photos .= '<input type="checkbox" id="facebook' . $i . '" name="photos[]" value="' . $sourceId . '"/>'; $photos .= '</li>'; $i++; } } catch (FacebookApiException $e) { echo '<p class="error-alert">' . T_('Could not get Facebook photos.') . '</p>'; $this->fcmsError->add(array('type' => 'operation', 'message' => T_('Could not get Facebook photos.'), 'error' => $e, 'file' => __FILE__, 'line' => __LINE__)); return; } if ($i <= 1 && empty($photos)) { $photos = '<p class="info-alert">' . T_('No photos were found in this album') . '</p>'; } echo $photos; }
/** * displayFacebookRegister * * @return void */ function handleFacebookRegister() { $fbData = getFacebookConfigData(); $fbProfile = ''; if (empty($fbData['fb_app_id']) && empty($fbData['fb_secret'])) { $this->displayHeader(); $this->displayHtmlForm(T_('Facebook isn\'t Configured Yet.')); $this->displayFooter(); return; } $facebook = new Facebook(array('appId' => $fbData['fb_app_id'], 'secret' => $fbData['fb_secret'])); // Check if the user is logged in and authed $fbUser = $facebook->getUser(); if ($fbUser) { try { $fbProfile = $facebook->api('/me'); } catch (FacebookApiException $e) { $fbUser = null; } } // the user's auth went away or logged out of fb, send them back to register form if (!$fbUser) { displayForm(); return; } // Register new user $accessToken = $facebook->getAccessToken(); $params = array('fname' => $fbProfile['first_name'], 'lname' => $fbProfile['last_name'], 'email' => $fbProfile['email'], 'sex' => $fbProfile['gender'] == 'male' ? 'M' : 'F', 'username' => $fbProfile['email'], 'password' => 'FACEBOOK', 'accessToken' => $accessToken); displaySubmit($params); }
/** * handleFacebookLogin * * @return void */ function handleFacebookLogin() { $fcmsError = FCMS_Error::getInstance(); $fcmsDatabase = Database::getInstance($fcmsError); $fcmsUser = User::getInstance($fcmsError, $fcmsDatabase); $fbData = getFacebookConfigData(); if (empty($fbData['fb_app_id']) || empty($fbData['fb_secret'])) { return; } $facebook = new Facebook(array('appId' => $fbData['fb_app_id'], 'secret' => $fbData['fb_secret'])); // Check if the user is logged in and authed $fbUser = $facebook->getUser(); $fbProfile = ''; if ($fbUser) { try { $fbProfile = $facebook->api('/me'); } catch (FacebookApiException $e) { $fbUser = null; } } // User isn't logged in, or authed if (!$fbUser) { return; } $sql = "SELECT u.`id`, u.`username`, u.`phpass`, u.`activated`, u.`locked`\n FROM `fcms_users` AS u, `fcms_user_settings` AS s\n WHERE s.`user` = u.`id`\n AND (\n u.`username` = ?\n OR s.`fb_access_token` = ?\n )"; $params = array($fbProfile['email'], $fbUser); $row = $fcmsDatabase->getRow($sql, $params); if ($row === false) { $fcmsError->displayError(); return; } if (empty($row)) { echo ' <div class="err-msg"> <h2>' . T_('Oops!') . '</h2> <p>' . T_('Your account hasn\'t been connected to Facebook yet. You need to connect your existing account with Facebook or register a new account using Facebook.') . '</p> </div>'; return; } // Check account is active if ($row['activated'] == 0) { displayNotActive(); die; // we don't want to return to displaying the login, we already did } // We made it past all the checks, then the user can be logged in if (!loginUser($row['id'], 0)) { $fcmsError->displayError(); return; } header("Location: home.php"); }
/** * getUploadTypesNavigation * * @param string $currentType * * @return string */ protected function getUploadTypesNavigation($currentType) { $nav = ''; $types = array('upload', 'facebook', 'picasa', 'instagram'); foreach ($types as $type) { $url = ''; $class = $currentType == $type ? 'current' : ''; $text = ''; if ($type == 'upload') { $type = getUploaderType($this->fcmsUser->id); $url = '?action=upload&type=' . $type; $text = T_('Computer'); } elseif ($type == 'instagram') { $config = getInstagramConfigData(); if (empty($config['instagram_client_id']) || empty($config['instagram_client_secret'])) { continue; } $url = '?action=upload&type=instagram'; $text = 'Instagram'; } elseif ($type == 'picasa') { $url = '?action=upload&type=picasa'; $text = 'Picasa'; } elseif ($type == 'facebook') { $config = getFacebookConfigData(); if (empty($config['fb_app_id']) && empty($config['fb_secret'])) { continue; } $url = '?action=upload&type=facebook'; $text = 'Facebook'; } else { die('Invalid upload type.'); } $nav .= ' <li class="' . $class . '"><a href="' . $url . '">' . $text . '</a></li>'; } return $nav; }
/** * displayEditFacebookSubmit * * @return void */ function displayEditFacebookSubmit() { $data = getFacebookConfigData(); if (!empty($data['fb_app_id']) && !empty($data['fb_secret'])) { $facebook = new Facebook(array('appId' => $data['fb_app_id'], 'secret' => $data['fb_secret'])); $fbUserId = $facebook->getUser(); if ($fbUserId) { try { $fbProfile = $facebook->api('/me'); } catch (FacebookApiException $e) { $fbUserId = null; } } $facebook->setExtendedAccessToken(); $accessToken = $facebook->getAccessToken(); $sql = "UPDATE `fcms_user_settings`\n SET `fb_access_token` = ?,\n `fb_user_id` = ?\n WHERE `user` = ?"; $params = array($accessToken, $fbUserId, $this->fcmsUser->id); if (!$this->fcmsDatabase->update($sql, $params)) { $this->displayHeader(); $this->fcmsError->displayError(); $this->displayFooter(); return; } } else { $this->displayHeader(); echo ' <div class="info-alert"> <h2>' . T_('Facebook isn\'t Configured Yet.') . '</h2> <p>' . T_('Unfortunately, your website administrator has not set up Facebook yet.') . '</p> </div>'; $this->displayFooter(); return; } header("Location: settings.php?view=facebook"); }
/** * display * * @return void */ public function display() { $_SESSION['fcms_uploader_type'] = 'facebook'; $config = getFacebookConfigData(); $accessToken = getUserFacebookAccessToken($this->fcmsUser->id); $facebook = new Facebook(array('appId' => $config['fb_app_id'], 'secret' => $config['fb_secret'])); $facebook->setAccessToken($accessToken); $fbUser = $facebook->getUser(); if ($fbUser) { try { $fbProfile = $facebook->api('/me'); } catch (FacebookApiException $e) { $fbUser = null; } } $facebookInfo = ''; $js = ''; if ($this->fcmsError->hasError()) { $this->fcmsError->displayError(); return; } elseif (!$fbUser) { $facebookInfo = ' <div class="info-alert"> <h2>' . T_('Not connected to Facebook.') . '</h2> <p>' . T_('You must connect your Family Connections account to Facebook before you can begin importing photos from Facebook.') . '</p> <p><a href="../settings.php?view=facebook">' . T_('Connect to Facebook') . '</a></p> </div>'; } else { try { $fbAlbums = $facebook->api('/me/albums'); $albumOptions = ''; foreach ($fbAlbums['data'] as $album) { $albumOptions .= '<option value="' . $album['id'] . '">' . $album['name'] . '</option>'; } } catch (FacebookApiException $e) { $this->fcmsError->add(array('type' => 'operation', 'message' => T_('Could not get Facebook albums.'), 'error' => $e, 'file' => __FILE__, 'line' => __LINE__)); $this->fcmsError->displayError(); return; } $facebookInfo = ' <p> <select id="albums" name="albums"> ' . $albumOptions . ' </select> </p> <div id="selector"> <a href="#" onclick="photoGallerySelectAll(event, \'facebook\');" id="select-all">' . T_('Select All') . '</a> <a href="#" onclick="photoGallerySelectNone(event, \'facebook\');" id="select-none">' . T_('Select None') . '</a> </div> <ul id="photo_list"></ul>'; $js = 'loadPhotoGalleryPhotos("facebook", "' . T_('Could not get Facebook photos.') . '");'; $js .= 'loadPhotoGalleryPhotoEvents("facebook", "' . T_('Could not get Facebook photos.') . '");'; } // Display the form echo ' <form method="post" class="photo-uploader" action="index.php?action=upload&type=facebook"> <div class="header"> <label>' . T_('Category') . '</label> ' . $this->getCategoryInputs() . ' </div> <ul class="upload-types"> ' . $this->getUploadTypesNavigation('facebook') . ' </ul> <div class="upload-area"> <div class="facebook"> ' . $facebookInfo . ' </div> </div> <div class="footer"> <input class="sub1" type="submit" value="' . T_('Upload') . '" id="submit-photos" name="facebook"/> </div> </form> <script type="text/javascript"> ' . $js . ' $("#submit-photos").click(function(e) { ' . $this->getJsUploadValidation() . ' }); </script>'; }
/** * displayStatusUpdateSubmit * * @return void */ function displayStatusUpdateSubmit() { $status = $_POST['status']; $parent = 0; // Submited blank form? if (empty($_POST['status'])) { header("Location: home.php"); return; } if (isset($_POST['parent'])) { $parent = (int) $_POST['parent']; } // Insert new status $sql = "INSERT INTO `fcms_status`\n (`user`, `status`, `parent`, `created`, `updated`)\n VALUES\n (?, ?, ?, NOW(), NOW())"; $params = array($this->fcmsUser->id, $status, $parent); if (!$this->fcmsDatabase->insert($sql, $params)) { $this->displayHeader(); $this->fcmsError->displayError(); $this->displayFooter(); return; } // If replying, update the orig status updated date, so it bumps up to the top of the list if ($parent > 0) { $sql = "UPDATE `fcms_status`\n SET `updated` = NOW()\n WHERE `id` = ?\n LIMIT 1;"; if (!$this->fcmsDatabase->update($sql, $parent)) { $this->displayHeader(); $this->fcmsError->displayError(); $this->displayFooter(); return; } } // Post to facebook if (isset($_POST['update_fb'])) { $data = getFacebookConfigData(); // Send status to facebook if (!empty($data['fb_app_id']) && !empty($data['fb_secret'])) { $facebook = new Facebook(array('appId' => $data['fb_app_id'], 'secret' => $data['fb_secret'])); // Check if the user is logged in and authed $user = $facebook->getUser(); if ($user) { try { $statusUpdate = $facebook->api('/me/feed', 'post', array('message' => $_POST['status'], 'cb' => '')); } catch (FacebookApiException $e) { printr($e); } } } } // Email members $sql = "SELECT u.`email`, s.`user` \n FROM `fcms_user_settings` AS s, `fcms_users` AS u \n WHERE `email_updates` = '1'\n AND u.`id` = s.`user`"; $rows = $this->fcmsDatabase->getRows($sql); if ($rows === false) { $this->displayHeader(); $this->fcmsError->displayError(); $this->displayFooter(); return; } if (count($rows) > 0) { $url = getDomainAndDir(); $headers = getEmailHeaders(); $name = getUserDisplayName($this->fcmsUser->id); foreach ($rows as $r) { $to = getUserDisplayName($r['user']); $subject = sprintf(T_('%s added a new status update.'), $name); $email = $r['email']; $msg = T_('Dear') . ' ' . $to . ', ' . $subject . ' ' . $url . 'home.php ---- ' . T_('To stop receiving these notifications, visit the following url and change your \'Email Update\' setting to No:') . ' ' . $url . 'settings.php '; mail($email, $subject, $msg, $headers); } } header("Location: home.php"); }
/** * setFormData * * Saves all the data passed in from the form upload. * * @param array $formData * * @return void */ public function setFormData($formData) { $this->formData = $formData; $albumId = $formData['albums']; $config = getFacebookConfigData(); $accessToken = getUserFacebookAccessToken($this->fcmsUser->id); $facebook = new Facebook(array('appId' => $config['fb_app_id'], 'secret' => $config['fb_secret'])); $facebook->setAccessToken($accessToken); try { $fbPhotos = $facebook->api("/{$albumId}/photos"); } catch (FacebookApiException $e) { $this->fcmsError->add(array('type' => 'operation', 'message' => T_('Could not get Facebook photos.'), 'error' => $e, 'file' => __FILE__, 'line' => __LINE__)); return false; } $this->albumFeed = $fbPhotos; }
/** * displayForm * * Displays the form for configuring a facebook app. * * @return void */ function displayForm() { $this->displayHeader(); if (isset($_SESSION['success'])) { echo ' <div class="alert-message success"> <a class="close" href="#" onclick="$(this).up(\'div\').hide(); return false;">×</a> ' . T_('Changes Updated Successfully') . ' </div>'; unset($_SESSION['success']); } $r = getFacebookConfigData(); $id = isset($r['fb_app_id']) ? $r['fb_app_id'] : ''; $secret = isset($r['fb_secret']) ? $r['fb_secret'] : ''; echo ' <div class="alert-message block-message info"> <h1>' . T_('Facebook Integration') . '</h1> <p> ' . T_('In order to integrate Family Connections with Facebook, you must create a new Facebook app, and configure that app in Family Connections.') . ' </p> </div>'; if (empty($id) || empty($secret)) { echo ' <div class="row"> <div class="span4"> <h2>' . T_('Step 1') . '</h2> <p> ' . T_('Got to Facebook and create a new Application.') . ' </p> </div> <div class="span12"> <h3><a href="http://www.facebook.com/developers/createapp.php">' . T_('Create Facebook Application') . '</a></h3> <p> ' . T_('You don\'t really have to fill out any additional information other than the application name.') . ' </p> </div> </div><!-- /row --> <p> </p> <p> </p> <p> </p> <div class="row"> <div class="span4"> <h2>' . T_('Step 2') . '</h2> <p> ' . T_('Fill out the form with the App Id and App Secret from your newly created Facebook Application.') . ' </p> </div> <div class="span12">'; } echo ' <form method="post" action="facebook.php"> <fieldset> <legend>' . T_('Facebook Application') . '</legend> <div class="clearfix"> <label for="id">' . T_('App ID') . '</label> <div class="input"> <input class="frm_text" type="text" name="id" id="id" size="50" value="' . cleanOutput($id) . '"/> </div> </div> <div class="clearfix"> <label for="secret">' . T_('App Secret') . '</label> <div class="input"> <input class="frm_text" type="text" name="secret" id="secret" size="50" value="' . cleanOutput($secret) . '"/> </div> </div> <div class="actions"> <input class="btn primary" type="submit" name="submit" value="' . T_('Save') . '"/> </div> </fieldset> </form>'; if (empty($id) || empty($secret)) { echo ' </div><!-- /span12 --> </div><!-- /row -->'; } $this->displayFooter(); }