Skip to content
This repository has been archived by the owner on Sep 18, 2021. It is now read-only.

Commit

Permalink
cleanup, improved accesstoken fetch, added documentation, german tran…
Browse files Browse the repository at this point in the history
…slation
  • Loading branch information
749 committed Oct 19, 2016
1 parent a68f718 commit dfcf769
Show file tree
Hide file tree
Showing 10 changed files with 872 additions and 22 deletions.
10 changes: 0 additions & 10 deletions assets/components/facebook_feed/js/feed.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,2 @@
if(!FB_Feed)
FB_Feed = {};

Ext.onReady(function() {
document.getElementById("FB_Login").onclick = function() {
FB.Login(function(response) {
if (response.authResponse) {
//reload the page to get managed pages
}
}, {scope: 'manage_pages'});
}
});
18 changes: 18 additions & 0 deletions core/components/facebook_feed/controllers/home.class.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
<?php
/**
* ModX Facebook Feed
* Allows you to easily display a Facebook pages' feed on your website.
* Copyright (C) 2016 Jan Giesenberg <giesenja@gmail.com>
*
* ModX Facebook Feed is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ModX Facebook Feed is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ModX Facebook Feed. If not, see <http://www.gnu.org/licenses/>.
*/

class Facebook_feedHomeManagerController extends Facebook_feedManagerController {
/**
Expand Down
16 changes: 16 additions & 0 deletions core/components/facebook_feed/docs/changelog.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
TODO
====
* write documentation on how to setup
* improve the token request manager package


Might do
========
* get the number of comments per post



Version 0.2.0-beta
==================
* basic functionality working
* added a way to request a client Token from the manager
675 changes: 675 additions & 0 deletions core/components/facebook_feed/docs/license.txt

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions core/components/facebook_feed/docs/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
ModX Facebook Feed
==================

This piece of Software will allow you to add a Facebook Feed from one of your
Facebook pages to your site. This is great for companies that want to update
clients using the Facebook page, but not want an ugly Facebook widget on their
page.


Requirements
============
* Tested with ModX 2.5.1
* Needs PHP 5.4 or newer (Facebook API)


Installation
============

1. Create a Facebook app using the Facebook for Developers page
https://developers.facebook.com/apps
2. Note down both the AppID and the App Secret
3. Install the package using the ModX package manager
During the installation you will be asked to provide the ID and Secret
of your Facebook app
4. Use the Facebook Feed manager page to request a valid access token from
facebook
5. Use the provided snippet to display a Feed on your page
18 changes: 18 additions & 0 deletions core/components/facebook_feed/index.class.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
<?php
/**
* ModX Facebook Feed
* Allows you to easily display a Facebook pages' feed on your website.
* Copyright (C) 2016 Jan Giesenberg <giesenja@gmail.com>
*
* ModX Facebook Feed is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ModX Facebook Feed is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ModX Facebook Feed. If not, see <http://www.gnu.org/licenses/>.
*/
require_once dirname(__FILE__) . '/model/fb_feed/feed.class.php';
/**
* @package facebook_feed
Expand Down
38 changes: 38 additions & 0 deletions core/components/facebook_feed/lexicon/de/default.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
/**
* ModX Facebook Feed
* Allows you to easily display a Facebook pages' feed on your website.
* Copyright (C) 2016 Jan Giesenberg <giesenja@gmail.com>
*
* ModX Facebook Feed is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ModX Facebook Feed is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ModX Facebook Feed. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* Default English language strings for Login
* @package login
* @subpackage lexicon
*/
$_lang['facebook_feed'] = 'Facebook Feed';
$_lang['facebook_feed_desc'] = 'Access Token erneuern';
$_lang['facebook_feed.ago'] = ' vor';
$_lang['facebook_feed.ago_days'] = '[[+days]] tage';
$_lang['facebook_feed.ago_hours'] = '[[+hours]] stunden';
$_lang['facebook_feed.ago_minutes'] = '[[+minutes]] min';
$_lang['facebook_feed.ago_seconds'] = '[[+seconds]] sek';

$_lang['setting_facebook_feed.app_id'] = 'Facebook Applikations ID';
$_lang['setting_facebook_feed.app_id_desc'] = 'Enter the ID of the Application given to you by Facebook.';
$_lang['setting_facebook_feed.app_secret'] = 'Facebook Applikations Secret';
$_lang['setting_facebook_feed.app_secret_desc'] = 'Enter the Secret of the Application given to you by Facebook.';
$_lang['setting_facebook_feed.access_token'] = 'Facebook Access Token(nicht verändern)';
$_lang['setting_facebook_feed.access_token_desc'] = 'This holds the generated Access Token for this application, do not change unless you know what you are doing.';
19 changes: 18 additions & 1 deletion core/components/facebook_feed/lexicon/en/default.inc.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
<?php

/**
* ModX Facebook Feed
* Allows you to easily display a Facebook pages' feed on your website.
* Copyright (C) 2016 Jan Giesenberg <giesenja@gmail.com>
*
* ModX Facebook Feed is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ModX Facebook Feed is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ModX Facebook Feed. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* Default English language strings for Login
* @package login
Expand Down
55 changes: 44 additions & 11 deletions core/components/facebook_feed/model/fb_feed/feed.class.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
<?php
/**
* ModX Facebook Feed
* Allows you to easily display a Facebook pages' feed on your website.
* Copyright (C) 2016 Jan Giesenberg <giesenja@gmail.com>
*
* ModX Facebook Feed is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ModX Facebook Feed is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ModX Facebook Feed. If not, see <http://www.gnu.org/licenses/>.
*/
require_once __DIR__.'/../Facebook/autoload.php';

class Feed {
Expand Down Expand Up @@ -55,9 +73,32 @@ protected function initFB() {
]);
}

public function getTokenURL() {
return 'https://graph.facebook.com/oauth/access_token?client_id=' . $this->config['app_id'] . '&client_secret=' . $this->app_secret . '&grant_type=client_credentials';
}

public function checkToken($token) {
$identifier = 'access_token=';
if(substr($token, 0, strlen($identifier)) === $identifier){
$token = substr($token, strlen($identifier) + 1);
}
if(strlen($token) == 0){
$this->modx->log(xPDO::LOG_LEVEL_ERROR, 'Error: Tried to install empty token');
return false;
}

$setting = $this->modx->getObject('modSystemSetting',array('key' => 'facebook_feed.access_token'));
if ($setting != null) {
$setting->set('value',$token);
$setting->save();
return true;
}
return false;
}

public function generateAccessToken() {
$curl = curl_init();
$url = 'https://graph.facebook.com/oauth/access_token?client_id='.$this->config['app_id'].'&client_secret='.$this->app_secret.'&grant_type=client_credentials';
$url = $this->getTokenURL();
//echo '<pre>'.$url.'</pre>';
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
Expand All @@ -67,19 +108,11 @@ public function generateAccessToken() {
));
$result = curl_exec($curl);
if(!$result){
$xpdo->log(xPDO::LOG_LEVEL_ERROR, 'Error: "' . curl_error($curl) . '" - Code: ' . curl_errno($curl));
$this->modx->log(xPDO::LOG_LEVEL_ERROR, 'Error: "' . curl_error($curl) . '" - Code: ' . curl_errno($curl));
return false;
}
curl_close($curl);
$token = substr($result, strpos($result, '=') + 1);

$setting = $this->modx->getObject('modSystemSetting',array('key' => 'facebook_feed.access_token'));
if ($setting != null) {
$setting->set('value',$options['app_id']);
$setting->save();
return true;
}
return false;
return $this->checkToken($result);
}

function calcTimeAgo($time) {
Expand Down
18 changes: 18 additions & 0 deletions core/components/facebook_feed/snippets/snippet.fb_feed.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
<?php
/**
* ModX Facebook Feed
* Allows you to easily display a Facebook pages' feed on your website.
* Copyright (C) 2016 Jan Giesenberg <giesenja@gmail.com>
*
* ModX Facebook Feed is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ModX Facebook Feed is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ModX Facebook Feed. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* Facebook_Feed
*
Expand Down

0 comments on commit dfcf769

Please sign in to comment.