/** * @param User $user * @return bool */ public function doesUserLikePage(User $user) { $this->facebook->setAccessToken($user->facebookAccessToken); try { return count($this->facebook->api("me/likes/{$this->pageId}")->data) !== 0; } catch (FacebookApiException $e) { return FALSE; // safe fallback } }
/** * Loads first data source. */ private function load() { if ($this->lastResult === NULL) { $this->lastResult = $this->facebook->api($this->pathOrParams, $this->method, $this->params); } elseif ($this->hasNextPage()) { $this->lastResult = $this->facebook->api($this->getNextPath()); } }
/** * Returns collections of data from data source at one page. * * @return ArrayHash */ public function getNextPage() { if ($this->lastResult === NULL) { $this->lastResult = $this->facebook->api($this->pathOrParams, $this->method, $this->params); } elseif ($this->hasNextPage()) { $this->lastResult = $this->facebook->api($this->getNextPath()); } else { $this->lastResult = ArrayHash::from(array('data' => [])); } return $this->lastResult ? $this->lastResult->data : ArrayHash::from(array('data' => [])); }
/** * @param array $params * @return NULL|ArrayHash */ public function getPermissions(array $params = array()) { $params = array_merge($params, array('access_token' => $this->facebook->getAccessToken())); try { $response = $this->facebook->api("/{$this->profileId}/permissions", 'GET', $params); if ($response && !empty($response->data[0])) { return ArrayHash::from($response->data[0]); } } catch (FacebookApiException $e) { return NULL; } }
/** * @param array $params * @return NULL|ArrayHash */ public function getPermissions(array $params = array()) { $params = array_merge($params, array('access_token' => $this->facebook->getAccessToken())); try { $response = $this->facebook->api("/{$this->profileId}/permissions", 'GET', $params); if ($response && !empty($response->data)) { $items = array(); if (isset($response->data[0]['permission'])) { foreach ($response->data as $permissionsItem) { $items[$permissionsItem->permission] = $permissionsItem->status === 'granted'; } } elseif (isset($response->data[0])) { $items = (array) $response->data[0]; } return ArrayHash::from($items); } } catch (FacebookApiException $e) { return NULL; } }
public function actionFacebook() { $this->setTitle("Registrace uživatele prostřednictvím Facebooku"); $fbUserId = $this->facebook->getUser(); $me = $this->facebook->api('/me', NULL, ['fields' => ['id', 'first_name', 'last_name', 'picture', 'email', 'gender', 'locale']]); if ($this->user->isLoggedIn()) { try { if ($this->facebookUserModel->exists($fbUserId)) { $this->flashMessage("Uživatel s tímto FacebookID již je v systému zaregistrován.", "danger"); $this->redirect("in"); } else { $this->facebookUserModel->add(array("user_id" => $this->user->id, "facebook_id" => $fbUserId, "username" => $me["first_name"] . " " . $me["last_name"], "email" => $me["email"])); $this->facebookUserModel->updateToken($fbUserId, $this->facebook->getAccessToken()); $this->flashMessage("K účtu bude možné se přihlašovat prostřednictvím Facebooku.", "success"); } } catch (Exception $e) { $this->flashMessage("Při ověřování uživatele došlo k chybě.", "danger"); } $this->restoreRequest($this->backlink); $this->redirect(':Front:Homepage:'); } else { $form = $this["facebookRegistrationForm"]; $form["id"]->setValue($me["id"]); $form["firstname"]->setValue($me["first_name"]); $form["lastname"]->setValue($me["last_name"]); $form["email"]->setValue($me["email"]); if ($me["gender"] == "male") { $form["gender"]->setValue("M"); } else { if ($me["gender"] == "female") { $form["gender"]->setValue("F"); } } $this->template->me = $me; } }