From e6bb69d9d35fa91dd5a731fd3e362cb18822dc1f Mon Sep 17 00:00:00 2001 From: Phyks Date: Sun, 18 Jan 2015 00:20:22 +0100 Subject: [PATCH] Templating and Account settings page --- Main.php | 89 ++------------ Pages/Account.php | 33 ++++-- Pages/Admin.php | 38 ------ Pages/Callback.php | 66 ----------- plugin.ini | 2 +- templates/default/account/facebook.tpl.php | 110 ------------------ .../default/account/facebook/menu.tpl.php | 1 - templates/default/admin/facebook.tpl.php | 55 --------- templates/default/admin/facebook/menu.tpl.php | 1 - .../content/syndication/icon/facebook.tpl.php | 1 - .../onboarding/connect/facebook.tpl.php | 19 --- 11 files changed, 35 insertions(+), 380 deletions(-) delete mode 100644 Pages/Admin.php delete mode 100644 Pages/Callback.php delete mode 100644 templates/default/account/facebook.tpl.php delete mode 100644 templates/default/account/facebook/menu.tpl.php delete mode 100644 templates/default/admin/facebook.tpl.php delete mode 100644 templates/default/admin/facebook/menu.tpl.php delete mode 100644 templates/default/content/syndication/icon/facebook.tpl.php delete mode 100644 templates/default/onboarding/connect/facebook.tpl.php diff --git a/Main.php b/Main.php index 521a0e7..c06cf0d 100644 --- a/Main.php +++ b/Main.php @@ -1,6 +1,6 @@ addPageHandler('facebook/deauth', '\IdnoPlugins\Facebook\Pages\Deauth'); - // Register the callback URL - \Idno\Core\site()->addPageHandler('facebook/callback', '\IdnoPlugins\Facebook\Pages\Callback'); - // Register admin settings - \Idno\Core\site()->addPageHandler('admin/facebook', '\IdnoPlugins\Facebook\Pages\Admin'); // Register settings page - \Idno\Core\site()->addPageHandler('account/facebook', '\IdnoPlugins\Facebook\Pages\Account'); + \Idno\Core\site()->addPageHandler('account/diaspora', '\IdnoPlugins\KnownDiaspora\Pages\Account'); /** Template extensions */ - // Add menu items to account & administration screens - \Idno\Core\site()->template()->extendTemplate('admin/menu/items', 'admin/facebook/menu'); - \Idno\Core\site()->template()->extendTemplate('account/menu/items', 'account/facebook/menu'); - \Idno\Core\site()->template()->extendTemplate('onboarding/connect/networks', 'onboarding/connect/facebook'); + // Add menu items to account screens + \Idno\Core\site()->template()->extendTemplate('account/menu/items', 'account/diaspora/menu'); } - function registerEventHooks() - { + /*function registerEventHooks() + { // TODO - \Idno\Core\site()->syndication()->registerService('facebook', function () { - return $this->hasFacebook(); + \Idno\Core\site()->syndication()->registerService('diaspora', function () { + return $this->hasDiaspora(); }, array('note', 'article', 'image', 'media','rsvp', 'bookmark')); - if ($this->hasFacebook()) { - if (is_array(\Idno\Core\site()->session()->currentUser()->facebook) && !array_key_exists('access_token', \Idno\Core\site()->session()->currentUser()->facebook)) { + if ($this->hasDiaspora()) { + if (is_array(\Idno\Core\site()->session()->currentUser()->diaspora) && !array_key_exists('access_token', \Idno\Core\site()->session()->currentUser()->facebook)) { foreach(\Idno\Core\site()->session()->currentUser()->facebook as $username => $details) { \Idno\Core\site()->syndication()->registerServiceAccount('facebook', $username, $details['name']); } @@ -180,66 +172,7 @@ } } }); - } - - /** - * Retrieve the URL to authenticate with Facebook - * @return string - */ - function getAuthURL() - { - $facebook = $this; - if ($facebookAPI = $facebook->connect()) { - return $facebookAPI->getLoginUrl(); - } - return ''; - } - - /** - * Connect to Facebook - * @return bool|FacebookAPI - */ - function connect($account_id = '') - { - if (!empty(\Idno\Core\site()->config()->facebook)) { - - require_once(dirname(__FILE__) . '/external/facebook-sdk/autoload.php'); - \Facebook\FacebookSession::setDefaultApplication( - \Idno\Core\site()->config()->facebook['appId'], - \Idno\Core\site()->config()->facebook['secret'] - ); - - $facebookAPI = new FacebookAPI(); - if (!empty($account_id)) { - if (!empty(\Idno\Core\site()->session()->currentUser()->facebook[$account_id])) { - $facebookAPI->setAccessToken(\Idno\Core\site()->session()->currentUser()->facebook[$account_id]['access_token']); - $this->endpoint = $account_id; - return $facebookAPI; - } - } else { - if (!empty(\Idno\Core\site()->session()->currentUser()->facebook['access_token'])) { - $facebookAPI->setAccessToken(\Idno\Core\site()->session()->currentUser()->facebook['access_token']); - } - return $facebookAPI; // This needs to return even if we haven't set the user token yet, for the auth callback - } - - } - - return false; - } - - /** - * Can the current user use Twitter? - * @return bool - */ - function hasFacebook() - { - if (!\Idno\Core\site()->session()->currentUser()) { - return false; - } - return \Idno\Core\site()->session()->currentUser()->facebook; - } - + }*/ } } diff --git a/Pages/Account.php b/Pages/Account.php index fa5dd10..9b07ee5 100644 --- a/Pages/Account.php +++ b/Pages/Account.php @@ -4,7 +4,7 @@ * Diaspora pages */ - namespace IdnoPlugins\Diaspora\Pages { + namespace IdnoPlugins\KnownDiaspora\Pages { /** * Default class to serve Diaspora-related account settings @@ -14,23 +14,36 @@ function getContent() { - $this->gatekeeper(); // Logged-in users only - if ($diaspora = \Idno\Core\site()->plugins()->get('Diaspora')) { - $login_url = $diaspora->getAuthURL(); + if(isset($_GET['remove'])) { + \Idno\Core\site()->config->config['diaspora'] = [ + 'diaspora_username' => '', + 'diaspora_password' => '', + 'diaspora_pod' => '' + ]; + \Idno\Core\site()->config()->save(); + \Idno\Core\site()->session()->addMessage('Your Diaspora credentials were removed.'); + $this->forward(\Idno\Core\site()->config()->getDisplayURL() . 'account/diaspora/'); } + $this->gatekeeper(); // Logged-in users only $t = \Idno\Core\site()->template(); - $body = $t->__(array('login_url' => $login_url))->draw('account/diaspora'); + $body = $t->__(array())->draw('account/diaspora'); $t->__(array('title' => 'Diaspora', 'body' => $body))->drawPage(); } function postContent() { $this->gatekeeper(); // Logged-in users only - if (($this->getInput('remove'))) { - $user = \Idno\Core\site()->session()->currentUser(); - $user->diaspora = array(); - $user->save(); - \Idno\Core\site()->session()->addMessage('Your Diaspora settings have been removed from your account.'); + $pod = $this->getInput('pod'); + $username = $this->getInput('user'); + $password = $this->getInput('pass'); + \Idno\Core\site()->config->config['diaspora'] = [ + 'diaspora_username' => $username, + 'diaspora_pod' => $pod + ]; + if (empty(\Idno\Core\site()->config->config['diaspora']['diaspora_password']) || !empty($password) ) { + \Idno\Core\site()->config->config['diaspora']['diaspora_password'] = $password; } + \Idno\Core\site()->config()->save(); + \Idno\Core\site()->session()->addMessage('Your Diaspora credentials were saved.'); $this->forward(\Idno\Core\site()->config()->getDisplayURL() . 'account/diaspora/'); } diff --git a/Pages/Admin.php b/Pages/Admin.php deleted file mode 100644 index 06745e8..0000000 --- a/Pages/Admin.php +++ /dev/null @@ -1,38 +0,0 @@ -adminGatekeeper(); // Admins only - $t = \Idno\Core\site()->template(); - $body = $t->draw('admin/diaspora'); - $t->__(array('title' => 'Diaspora', 'body' => $body))->drawPage(); - } - - function postContent() { - $this->adminGatekeeper(); // Admins only - $appId = $this->getInput('appId'); - $secret = $this->getInput('secret'); - \Idno\Core\site()->config->config['diaspora'] = array( - 'appId' => $appId, - 'secret' => $secret - ); - \Idno\Core\site()->config()->save(); - \Idno\Core\site()->session()->addMessage('Your Diaspora application details were saved.'); - $this->forward(\Idno\Core\site()->config()->getDisplayURL() . 'admin/diaspora/'); - } - - } - - } diff --git a/Pages/Callback.php b/Pages/Callback.php deleted file mode 100644 index edea8c3..0000000 --- a/Pages/Callback.php +++ /dev/null @@ -1,66 +0,0 @@ -gatekeeper(); // Logged-in users only - if ($diaspora = \Idno\Core\site()->plugins()->get('Diaspora')) { - if ($diasporaAPI = $diaspora->connect()) { - /* @var \IdnoPlugins\diaspora\diasporaAPI $diasporaAPI */ - if ($session = $diasporaAPI->getSessionOnLogin()) { - $user = \Idno\Core\site()->session()->currentUser(); - $access_token = $session->getToken(); - $diasporaAPI->setAccessToken($access_token); - if ($person = $diasporaAPI->api('/me','GET')) { - $name = $person['response']->getProperty('name'); - $id = $person['response']->getProperty('id'); - $user->diaspora[$id] = ['id' => $id, 'access_token' => $access_token, 'name' => $name]; - \Idno\Core\site()->syndication()->registerServiceAccount('diaspora', $id, $name); - if (\Idno\Core\site()->config()->multipleSyndicationAccounts()) { - if ($companies = $diasporaAPI->api('/me/accounts','GET')) { - if (!empty($companies['response'])) { - foreach($companies['response']->asArray() as $company_container) { - foreach($company_container as $company) { - $company = (array) $company; - if ($perms = $company['perms']) { - if (in_array('CREATE_CONTENT', $perms) && !empty($company['name'])) { - $id = $company['id']; - $name = $company['name']; - $access_token = $company['access_token']; - $user->diaspora[$id] = ['id' => $id, 'access_token' => $access_token, 'name' => $name, 'page' => true]; - \Idno\Core\site()->syndication()->registerServiceAccount('diaspora', $id, $name); - } - } - } - } - } - } - } - } else { - $user->diaspora = array('access_token' => $access_token); - } - $user->save(); - } - } - } - if (!empty($_SESSION['onboarding_passthrough'])) { - unset($_SESSION['onboarding_passthrough']); - $this->forward(\Idno\Core\site()->config()->getURL() . 'begin/connect-forwarder'); - } - $this->forward(\Idno\Core\site()->config()->getDisplayURL() . 'account/diaspora/'); - } - - } - - } diff --git a/plugin.ini b/plugin.ini index 87e378d..76a6e55 100644 --- a/plugin.ini +++ b/plugin.ini @@ -1,5 +1,5 @@ [Plugin description] -name = "Diaspora" +name = "KnownDiaspora" version = 0.1 author = "Lucas Verney (Phyks)" author_email = "phyks@phyks.me" diff --git a/templates/default/account/facebook.tpl.php b/templates/default/account/facebook.tpl.php deleted file mode 100644 index ddf1f6c..0000000 --- a/templates/default/account/facebook.tpl.php +++ /dev/null @@ -1,110 +0,0 @@ -
- -
- draw('account/menu') ?> -

Facebook

- -
- -
-
-
- session()->currentUser()->facebook)) { - ?> -
-
-
-
-

- Easily share pictures, updates, and posts to Facebook.

- -

- With Facebook connected, you can cross-post content that you publish publicly on - your site. -

-
-
- -
-
- -
-
-
-
-

- Your account is currently connected to Facebook. - Public updates, pictures, and posts that you publish - here can be cross-posted to Facebook. - -

- - syndication()->getServiceAccounts('facebook')) { - - foreach ($accounts as $id => $account) { - - ?> - - - - -

- Add another Facebook account -

-
-
- - -
-
- -
-
diff --git a/templates/default/account/facebook/menu.tpl.php b/templates/default/account/facebook/menu.tpl.php deleted file mode 100644 index b3e44e2..0000000 --- a/templates/default/account/facebook/menu.tpl.php +++ /dev/null @@ -1 +0,0 @@ -
  • >Facebook
  • \ No newline at end of file diff --git a/templates/default/admin/facebook.tpl.php b/templates/default/admin/facebook.tpl.php deleted file mode 100644 index e282b72..0000000 --- a/templates/default/admin/facebook.tpl.php +++ /dev/null @@ -1,55 +0,0 @@ -
    - -
    - draw('admin/menu')?> -

    Facebook configuration

    - -
    - -
    -
    -
    -
    -
    -
    -

    - To begin using Facebook, create a new application in - the Facebook apps portal.

    -

    - Mark the Platform as Website, and use config()->url?> - as the site URL. Be sure to also include an email address. Then, click Status & Review, and make the app public. -

    -

    - Once you've finished, fill in the details below. You can then connect your Facebook account. -

    -
    -
    -
    - -
    - -
    -
    -
    - -
    - -
    -
    - - -
    -

    - After the Facebook application is configured, you must connect under account Settings. -

    - -
    -
    -
    - -
    -
    - actions()->signForm('/admin/facebook/')?> -
    -
    -
    diff --git a/templates/default/admin/facebook/menu.tpl.php b/templates/default/admin/facebook/menu.tpl.php deleted file mode 100644 index a1559c5..0000000 --- a/templates/default/admin/facebook/menu.tpl.php +++ /dev/null @@ -1 +0,0 @@ -
  • >Facebook
  • diff --git a/templates/default/content/syndication/icon/facebook.tpl.php b/templates/default/content/syndication/icon/facebook.tpl.php deleted file mode 100644 index 9be6a6b..0000000 --- a/templates/default/content/syndication/icon/facebook.tpl.php +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/templates/default/onboarding/connect/facebook.tpl.php b/templates/default/onboarding/connect/facebook.tpl.php deleted file mode 100644 index d0b5f92..0000000 --- a/templates/default/onboarding/connect/facebook.tpl.php +++ /dev/null @@ -1,19 +0,0 @@ -plugins()->get('Facebook')) { - if (empty(\Idno\Core\site()->session()->currentUser()->facebook)) { - $login_url = $facebook->getAuthURL(); - } else { - $login_url = \Idno\Core\site()->config()->getURL() . 'facebook/deauth'; - } - } - -?> -
    - Facebooksession()->currentUser()->facebook)) { echo ' - connected!'; } ?>
    - -
    \ No newline at end of file