Skip to content

Commit

Permalink
[FEATURE][#12][2.1.0]
Browse files Browse the repository at this point in the history
move constructors to parent class
move getCategory to parent class
get Token via &state parameter
update documentation
add Redirect script
  • Loading branch information
siwa-pparzer committed Apr 11, 2018
1 parent 19e6394 commit d997a82
Show file tree
Hide file tree
Showing 19 changed files with 117 additions and 154 deletions.
22 changes: 12 additions & 10 deletions Classes/Controller/Wizard/TokenController.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,21 +130,23 @@ public function main($request)
false,
true
);

if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off'){
$base = 'https' . '://' . $_SERVER['SERVER_NAME'];
}else{
$base = 'http' . '://' . $_SERVER['SERVER_NAME'];
}
if(strpos($redirectUrl, "://") === false) {
//$base = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https' : 'http' . '://' . $_SERVER['SERVER_NAME'];
if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off'){
$base = 'https' . '://' . $_SERVER['SERVER_NAME'];
}else{
$base = 'http' . '://' . $_SERVER['SERVER_NAME'];
}
$redirectUrl = $base . $redirectUrl;
}

$accessUrl = $utility->getAccessUrl().urlencode($redirectUrl);
$actualUrl = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$actualUrl = $base . $_SERVER['REQUEST_URI'];
$accessUrl = $utility->getAccessUrl($redirectUrl);

$tokenString = $utility->retrieveToken($actualUrl);

if(!$tokenString) {
//header('Location: '.$accessUrl);
$this->content .= $utility->getTokenJavascript($accessUrl, $actualUrl);
}else{
$res = $utility->getValues($tokenString);
Expand All @@ -163,7 +165,7 @@ public function main($request)
window.opener.document.querySelector(selectorExpHidden).value = '".$exp."';
close();
} else {
close();
alert('Got Token, but cant write to window');
}
</script>
Expand Down
4 changes: 3 additions & 1 deletion Classes/Utility/BaseUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ public static function initTSFE($id = 1, $typeNum = 0) {
if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('realurl')) {
$rootline = \TYPO3\CMS\Backend\Utility\BackendUtility::BEgetRootLine($id);
$host = \TYPO3\CMS\Backend\Utility\BackendUtility::firstDomainRecord($rootline);
$_SERVER['HTTP_HOST'] = $host;
if (!is_null($host)) {
$_SERVER['HTTP_HOST'] = $host;
}
}
}
public function initSettings(){
Expand Down
23 changes: 0 additions & 23 deletions Classes/Utility/Feed/FacebookUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,6 @@
class FacebookUtility extends \Socialstream\SocialStream\Utility\Feed\FeedUtility
{

/**
* __construct
*/
public function __construct($pid=0)
{
if($pid) {
$this->initTSFE($pid, 0);
$this->initSettings();
}
}

public function getChannel(\Socialstream\SocialStream\Domain\Model\Channel $channel,$isProcessing=0)
{
$url = "https://graph.facebook.com/".$channel->getObjectId()."/?fields=id,name,about,link,picture,cover&access_token=".$channel->getToken();
Expand Down Expand Up @@ -217,16 +206,4 @@ public function getFeed(\Socialstream\SocialStream\Domain\Model\Channel $channel
}
}
}
protected function getCategory($type,\GeorgRinger\News\Domain\Model\Category $parent = NULL){
$title = $this->getType($type);
$cat = $this->categoryRepository->findOneByTitle($title);
if(!$cat){
$cat = new \GeorgRinger\News\Domain\Model\Category();
$cat->setTitle($title);
if($parent)$cat->setParentcategory($parent);
$this->categoryRepository->add($cat);
$this->persistenceManager->persistAll();
}
return $cat;
}
}
26 changes: 26 additions & 0 deletions Classes/Utility/Feed/FeedUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ class FeedUtility extends \Socialstream\SocialStream\Utility\BaseUtility
* @var array
*/
public $clearStrings = array('\ud83c\u','\ud83d\u','\ud83e\u','\u2600\u');

/**
* __construct
*/
public function __construct($pid=0)
{
if($pid) {
$this->initTSFE($pid, 0);
$this->initSettings();
}
}

public static function initTSFE($id = 1, $typeNum = 0) {
parent::initTSFE($id,$typeNum);
Expand Down Expand Up @@ -220,4 +231,19 @@ public function addFlashMessage($txt,$head,$type,$obj){
$messageQueue->addMessage($message);
}

protected function getCategory($type,\GeorgRinger\News\Domain\Model\Category $parent = NULL){
$title = $this->getType($type);

$cat = $this->categoryRepository->findOneByTitle($title);

if(!$cat){
$cat = new \GeorgRinger\News\Domain\Model\Category();
$cat->setTitle($title);
if($parent)$cat->setParentcategory($parent);
$this->categoryRepository->add($cat);
$this->persistenceManager->persistAll();
}
return $cat;
}

}
23 changes: 0 additions & 23 deletions Classes/Utility/Feed/FlickrUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,6 @@
class FlickrUtility extends \Socialstream\SocialStream\Utility\Feed\FeedUtility
{

/**
* __construct
*/
public function __construct($pid=0)
{
if($pid) {
$this->initTSFE($pid, 0);
$this->initSettings();
}
}

public function getChannel(\Socialstream\SocialStream\Domain\Model\Channel $channel,$isProcessing=0)
{

Expand Down Expand Up @@ -170,16 +159,4 @@ public function getFeed(\Socialstream\SocialStream\Domain\Model\Channel $channel
$this->persistenceManager->persistAll();
}
}
protected function getCategory($type,\GeorgRinger\News\Domain\Model\Category $parent = NULL){
$title = $this->getType($type);
$cat = $this->categoryRepository->findOneByTitle($title);
if(!$cat){
$cat = new \GeorgRinger\News\Domain\Model\Category();
$cat->setTitle($title);
if($parent)$cat->setParentcategory($parent);
$this->categoryRepository->add($cat);
$this->persistenceManager->persistAll();
}
return $cat;
}
}
25 changes: 0 additions & 25 deletions Classes/Utility/Feed/InstagramUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,6 @@
class InstagramUtility extends \Socialstream\SocialStream\Utility\Feed\FeedUtility
{

/**
* __construct
*/
public function __construct($pid=0)
{
if($pid) {
$this->initTSFE($pid, 0);
$this->initSettings();
}
}

public function getChannel(\Socialstream\SocialStream\Domain\Model\Channel $channel,$isProcessing=0)
{
$url = "https://api.instagram.com/v1/users/".$channel->getObjectId()."/?access_token=".$channel->getToken();
Expand Down Expand Up @@ -226,18 +215,4 @@ public function getFeed(\Socialstream\SocialStream\Domain\Model\Channel $channel
$this->persistenceManager->persistAll();
}
}
protected function getCategory($type,\GeorgRinger\News\Domain\Model\Category $parent = NULL){
$title = $this->getType($type);

$cat = $this->categoryRepository->findOneByTitle($title);

if(!$cat){
$cat = new \GeorgRinger\News\Domain\Model\Category();
$cat->setTitle($title);
if($parent)$cat->setParentcategory($parent);
$this->categoryRepository->add($cat);
$this->persistenceManager->persistAll();
}
return $cat;
}
}
25 changes: 0 additions & 25 deletions Classes/Utility/Feed/TwitterUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,6 @@
class TwitterUtility extends \Socialstream\SocialStream\Utility\Feed\FeedUtility
{

/**
* __construct
*/
public function __construct($pid=0)
{
if($pid) {
$this->initTSFE($pid, 0);
$this->initSettings();
}
}

public function getChannel(\Socialstream\SocialStream\Domain\Model\Channel $channel,$isProcessing=0)
{
$ch = curl_init("https://api.twitter.com/1.1/users/show.json?user_id=" . $channel->getObjectId());
Expand Down Expand Up @@ -256,18 +245,4 @@ public function getFeed(\Socialstream\SocialStream\Domain\Model\Channel $channel

}
}
protected function getCategory($type,\GeorgRinger\News\Domain\Model\Category $parent = NULL){
$title = $this->getType($type);

$cat = $this->categoryRepository->findOneByTitle($title);

if(!$cat){
$cat = new \GeorgRinger\News\Domain\Model\Category();
$cat->setTitle($title);
if($parent)$cat->setParentcategory($parent);
$this->categoryRepository->add($cat);
$this->persistenceManager->persistAll();
}
return $cat;
}
}
15 changes: 4 additions & 11 deletions Classes/Utility/Token/FacebookUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,11 @@
*/
class FacebookUtility extends \Socialstream\SocialStream\Utility\Token\TokenUtility
{
/**
* __construct
*/
public function __construct($pid)
{
$this->initTSFE($pid,0);
$this->initSettings();
}

public function getAccessUrl()
public function getAccessUrl($redirect)
{
$url = "https://www.facebook.com/v2.4/dialog/oauth?client_id=" . $this->settings["fbappid"] . "&state=" . $this->settings["fbappsecret"] . "&response_type=token&scope=user_posts&sdk=php-sdk-5.0.0&redirect_uri=";
//$url = "https://www.facebook.com/v2.5/dialog/oauth?client_id=" . $this->settings["fbappid"] . "&state=" . $this->settings["fbappsecret"] . "&response_type=token&scope=user_posts&sdk=php-sdk-5.0.0&redirect_uri=";
$url_parts = $this->splitRedirectUrl($redirect);
$url = "https://www.facebook.com/v2.12/dialog/oauth?client_id=" . $this->settings["fbappid"] . "&state=" . $url_parts["state"] . "&response_type=token&scope=user_posts&sdk=php-sdk-5.0.0&redirect_uri=".$url_parts["base"];
return $url;
}
public function getTokenJavascript($accessUrl,$actualUrl){
Expand Down
12 changes: 2 additions & 10 deletions Classes/Utility/Token/FlickrUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,10 @@
*/
class FlickrUtility extends \Socialstream\SocialStream\Utility\Token\TokenUtility
{
/**
* __construct
*/
public function __construct($pid)
{
$this->initTSFE($pid,0);
$this->initSettings();
}

public function getAccessUrl()
public function getAccessUrl($redirect)
{
return "not in use";
return $redirect;
}
public function getTokenJavascript($accessUrl,$actualUrl){
return "should not be called";
Expand Down
14 changes: 3 additions & 11 deletions Classes/Utility/Token/InstagramUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,10 @@
*/
class InstagramUtility extends \Socialstream\SocialStream\Utility\Token\TokenUtility
{
/**
* __construct
*/
public function __construct($pid)
public function getAccessUrl($redirect)
{
$this->initTSFE($pid,0);
$this->initSettings();
}

public function getAccessUrl()
{
$url = "https://api.instagram.com/oauth/authorize/?client_id=" . $this->settings["instaappid"] . "&response_type=token&redirect_uri=";
$url_parts = $this->splitRedirectUrl($redirect);
$url = "https://api.instagram.com/oauth/authorize/?client_id=" . $this->settings["instaappid"] . "&response_type=token&state=" . $url_parts["state"] . "&redirect_uri=".$url_parts["base"];
return $url;
}
public function getTokenJavascript($accessUrl,$actualUrl){
Expand Down
16 changes: 15 additions & 1 deletion Classes/Utility/Token/TokenUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@
*/
class TokenUtility extends \Socialstream\SocialStream\Utility\BaseUtility
{
/**
* __construct
*/
public function __construct($pid)
{
$this->initTSFE($pid,0);
$this->initSettings();
}

public static function initTSFE($id = 1, $typeNum = 0) {
parent::initTSFE($id,$typeNum);
}
Expand All @@ -42,5 +51,10 @@ public static function getUtility($type,$pid=0){
$classname = "\\Socialstream\\SocialStream\\Utility\\Token\\".ucfirst($type)."Utility";
return new $classname($pid);
}

public function splitRedirectUrl($url){
$url_parts = explode("?",$url);
$params = str_replace("&",",",$url_parts[1]);
$base = explode("/typo3/",$url_parts[0]);
return array("base"=>$base[0]."/typo3conf/ext/social_stream/Redirect.php","state"=>$params);
}
}
13 changes: 2 additions & 11 deletions Classes/Utility/Token/TwitterUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,9 @@
*/
class TwitterUtility extends \Socialstream\SocialStream\Utility\Token\TokenUtility
{
/**
* __construct
*/
public function __construct($pid)
public function getAccessUrl($redirect)
{
$this->initTSFE($pid,0);
$this->initSettings();
}

public function getAccessUrl()
{
return "not in use";
return $redirect;
}
public function getTokenJavascript($accessUrl,$actualUrl){
return "should not be called";
Expand Down
1 change: 1 addition & 0 deletions Documentation/Channels/Facebook/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Go to https://developers.facebook.com/apps/

- Click 'Settings' on the Left
- Check that the settings look like Image 1
- For your valid OAuth Redirect Uri enter 'http://your-domain.com/typo3conf/ext/social_stream/Redirect.php'
- Save (bottom right corner)

.. figure:: ../Images/screen-fb-api.jpg
Expand Down
3 changes: 3 additions & 0 deletions Documentation/Configuration/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
Configuration Reference
=======================

Make sure you have set a sys_domain record on your Root Page


TYPOSCRIPT
----------

Expand Down
1 change: 0 additions & 1 deletion Documentation/Developer/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ add Classes/Utility/Feed/**Foo**Utility.php
- `getChannel`
- `renewToken`
- `getFeed`
- `getCategory`

best practice: copy the FacebookUtility

Expand Down
3 changes: 3 additions & 0 deletions Documentation/Introduction/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ Social Stream crawls the data from a Social Media Page and saves it as news reco

- Facebook User/Page
- Facebook Event
- Instagram
- Flickr
- Twitter


.. _screenshots:
Expand Down
Loading

0 comments on commit d997a82

Please sign in to comment.