X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=actions%2Ffacebookhome.php;h=34989c9786aa9814f9396d49bcba0db3934e9af3;hb=9f079764aa945e9e126ffa41cece17bc8951fb78;hp=b05e51b9114aa6c9c8cc7074bd2722bc5853dda8;hpb=240231a8bd7f6b0753070c630ff6b9169e28afe0;p=quix0rs-gnu-social.git diff --git a/actions/facebookhome.php b/actions/facebookhome.php index b05e51b911..34989c9786 100644 --- a/actions/facebookhome.php +++ b/actions/facebookhome.php @@ -1,7 +1,7 @@ page = $this->trimmed('page'); - + if (!$this->page) { $this->page = 1; } - + return true; } function handle($args) { - parent::handle($args); - + parent::handle($args); + // If the user has opted not to initially allow the app to have // Facebook status update permission, store that preference. Only // promt the user the first time she uses the app - if ($this->arg('skip')) { + if ($this->arg('skip') || $args['fb_sig_request_method'] == 'GET') { $this->facebook->api_client->data_setUserPreference( FACEBOOK_PROMPTED_UPDATE_PREF, 'true'); } @@ -57,30 +56,31 @@ class FacebookhomeAction extends FacebookAction $this->user = $this->flink->getUser(); // If this is the first time the user has started the app - // prompt for Facebook status update permission - if (!$this->facebook->api_client->users_hasAppPermission('status_update')) { + // prompt for Facebook status update permission + if (!$this->facebook->api_client->users_hasAppPermission('status_update')) { if ($this->facebook->api_client->data_getUserPreference( - FACEBOOK_PROMPTED_UPDATE_PREF) != 'true') { - $this->getUpdatePermission(); - return; + FACEBOOK_PROMPTED_UPDATE_PREF) != 'true') { + $this->getUpdatePermission(); + return; } } // Make sure the user's profile box has the lastest notice $notice = $this->user->getCurrentNotice(); - $this->updateProfileBox($notice); + if ($notice) { + $this->updateProfileBox($notice); + } - if ($this->arg('status_submit') == 'Send') { + if ($this->arg('status_submit') == 'Send') { $this->saveNewNotice(); - } + } // User is authenticated and has already been prompted once for // Facebook status update permission? Then show the main page // of the app $this->showPage(); - } else { // User hasn't authenticated yet, prompt for creds @@ -91,9 +91,9 @@ class FacebookhomeAction extends FacebookAction function login() { - + $this->showStylesheets(); - + $nickname = common_canonical_nickname($this->trimmed('nickname')); $password = $this->arg('password'); @@ -114,14 +114,13 @@ class FacebookhomeAction extends FacebookAction $flink->foreign_id = $this->fbuid; $flink->service = FACEBOOK_SERVICE; $flink->created = common_sql_now(); - $flink->set_flags(true, false, false); + $flink->set_flags(true, false, false, false); $flink_id = $flink->insert(); // XXX: Do some error handling here $this->setDefaults(); - //$this->showHome($flink, _('You can now use Identi.ca from Facebook!')); $this->getUpdatePermission(); return; @@ -132,25 +131,21 @@ class FacebookhomeAction extends FacebookAction } $this->showLoginForm($msg); + $this->showFooter(); } function setDefaults() { - // A default prefix string for notices - $this->facebook->api_client->data_setUserPreference( - FACEBOOK_NOTICE_PREFIX, 'dented: '); $this->facebook->api_client->data_setUserPreference( FACEBOOK_PROMPTED_UPDATE_PREF, 'false'); } - function showNoticeForm() { - $post_action = "$this->app_uri/index.php"; - - $notice_form = new FacebookNoticeForm($this, $post_action, null, + + $notice_form = new FacebookNoticeForm($this, $post_action, null, $post_action, $this->user); $notice_form->show(); } @@ -166,22 +161,19 @@ class FacebookhomeAction extends FacebookAction function showContent() { + $notice = $this->user->noticeInbox(($this->page-1) * NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1); - $notice = $this->user->noticesWithFriends(($this->page-1) * - NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1); - $nl = new NoticeList($notice, $this); $cnt = $nl->show(); $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE, $this->page, 'index.php', array('nickname' => $this->user->nickname)); - } function showNoticeList($notice) { - + $nl = new NoticeList($notice, $this); return $nl->show(); } @@ -190,7 +182,7 @@ class FacebookhomeAction extends FacebookAction $this->showStylesheets(); - $this->elementStart('div', array('class' => 'content')); + $this->elementStart('div', array('class' => 'facebook_guide')); $instructions = sprintf(_('If you would like the %s app to automatically update ' . 'your Facebook status with your latest notice, you need ' . @@ -201,16 +193,24 @@ class FacebookhomeAction extends FacebookAction $this->elementEnd('p'); $this->elementStart('form', array('method' => 'post', - 'action' => $app_url, + 'action' => "index.php", 'id' => 'facebook-skip-permissions')); $this->elementStart('ul', array('id' => 'fb-permissions-list')); $this->elementStart('li', array('id' => 'fb-permissions-item')); - $this->elementStart('fb:prompt-permission', array('perms' => 'status_update', - 'next_fbjs' => 'document.setLocation(\'' . $this->app_uri . '\')')); - $this->element('span', array('class' => 'facebook-button'), - sprintf(_('Allow %s to update my Facebook status'), $this->app_name)); - $this->elementEnd('fb:prompt-permission'); + + $next = urlencode("$this->app_uri/index.php"); + $api_key = common_config('facebook', 'apikey'); + + $auth_url = 'http://www.facebook.com/authorize.php?api_key=' . + $api_key . '&v=1.0&ext_perm=status_update&next=' . $next . + '&next_cancel=' . $next . '&submit=skip'; + + $this->elementStart('span', array('class' => 'facebook-button')); + $this->element('a', array('href' => $auth_url), + sprintf(_('Okay, do it!'), $this->app_name)); + $this->elementEnd('span'); + $this->elementEnd('li'); $this->elementStart('li', array('id' => 'fb-permissions-item')); @@ -223,53 +223,6 @@ class FacebookhomeAction extends FacebookAction } - function saveNewNotice() - { - - $user = $this->flink->getUser(); - - $content = $this->trimmed('status_textarea'); - - if (!$content) { - $this->showPage(_('No notice content!')); - return; - } else { - $content_shortened = common_shorten_links($content); - - if (mb_strlen($content_shortened) > 140) { - common_debug("Content = '$content_shortened'", __FILE__); - common_debug("mb_strlen(\$content) = " . mb_strlen($content_shortened), __FILE__); - $this->showPage(_('That\'s too long. Max notice size is 140 chars.')); - return; - } - } - - $inter = new CommandInterpreter(); - - $cmd = $inter->handle_command($user, $content_shortened); - - if ($cmd) { - - // XXX fix this - - $cmd->execute(new WebChannel()); - return; - } - - $replyto = $this->trimmed('inreplyto'); - - $notice = Notice::saveNew($user->id, $content, - 'Facebook', 1, ($replyto == 'false') ? null : $replyto); - - if (is_string($notice)) { - $this->showPage($notice); - return; - } - - common_broadcast_notice($notice); - - } - /** * Generate pagination links * @@ -283,11 +236,11 @@ class FacebookhomeAction extends FacebookAction */ function pagination($have_before, $have_after, $page, $action, $args=null) { - + // Does a little before-after block for next/prev page - + // XXX: Fix so this uses common_local_url() if possible. - + if ($have_before || $have_after) { $this->elementStart('div', array('class' => 'pagination')); $this->elementStart('dl', null); @@ -298,7 +251,7 @@ class FacebookhomeAction extends FacebookAction if ($have_before) { $pargs = array('page' => $page-1); $newargs = $args ? array_merge($args, $pargs) : $pargs; - $this->elementStart('li', array('class' => 'nav_prev')); + $this->elementStart('li', array('class' => 'nav_prev')); $this->element('a', array('href' => "$action?page=$newargs[page]", 'rel' => 'prev'), _('After')); $this->elementEnd('li'); @@ -318,6 +271,5 @@ class FacebookhomeAction extends FacebookAction $this->elementEnd('div'); } } - }