facebook-login-javascript

window.fbAsyncInit = function() {
    FB.init({
        appId      : '185972185972',
        cookie     : true,
        xfbml      : true,  
        version    : 'v2.8' 
    });
    FB.getLoginStatus(function(response) {
        FBstatusChangeCallback(response);
    });
};

(function(d, s, id) {
    var js, fjs = d.getElementsByTagName(s)[0];
    if (d.getElementById(id)) return;
    js = d.createElement(s); js.id = id;
    js.src = "//connect.facebook.net/en_US/sdk.js";
    fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

function FBstatusChangeCallback(response) {
    if (response.status === 'connected') {
        FBresponseFromGraph(response.authResponse.accessToken);
    } else {
        document.getElementById('FBerror').innerHTML =  'not connected';
    }
}

function FBcheckFacebookLoginState() {
    FB.getLoginStatus(function(response) {
        FBstatusChangeCallback(response);
    });
}

function FBresponseFromGraph(accessToken) {
	document.getElementById('accessToken').value =  accessToken;
    FB.api('/me?fields=id,email,first_name,last_name', function(response) {
        document.getElementById('first_name').value =  response.first_name;
        document.getElementById('last_name').value =  response.last_name;
        document.getElementById('email').value =  response.email;        
    });
}
<fb:login-button scope="public_profile,email" onlogin="FBcheckFacebookLoginState();">
</fb:login-button>
<div id="accessToken"></div>
<div id="first_name"></div>
<div id="last_name"></div>
<div id="email"></div>
<div id="FBerror"></div>

Facebook Login PHP

config.php

/*
 * FACEBOOK-LOGIN-SETUP
 * https://developers.facebook.com/docs/graph-api/reference/user
 * APP-ID on https://developers.facebook.com/apps/
 * 1. Create a new FB-APP
 * 2. GET the app_id & app_secret
 * 3. ADD Plattform => set Domain for LOGIN
 */
$config = array();
// App-ID
$config['facebook']['app_id'] = '1s59724s57582812';
$config['facebook']['app_secret'] = 'f302eabf302eabf302eabf302eab';
$config['facebook']['callpack_url'] = 'http://login.infochy.de/callback.php';

login.php

require_once 'config.php';
session_start() ;
require_once __DIR__ . '/vendor/php-graph-sdk-5.0.0/src/Facebook/autoload.php';

$fb = new Facebook\Facebook([
'app_id' => $config['facebook']['app_id'], 
'app_secret' => $config['facebook']['app_secret'],
'default_graph_version' => 'v2.2',
]);

$helper = $fb->getRedirectLoginHelper();

$permissions = ['email']; // Optional permissions
$loginUrl = $helper->getLoginUrl($config['facebook']['callpack_url'], $permissions);

echo '<a href="' . htmlspecialchars($loginUrl) . '">Log in with Facebook!</a>';

callback.php

require_once 'config.php';
session_start() ;
require_once __DIR__ . '/vendor/php-graph-sdk-5.0.0/src/Facebook/autoload.php';

$fb = new Facebook\Facebook([
    'app_id' => $config['facebook']['app_id'], // Replace {app-id} with your app id
    'app_secret' => $config['facebook']['app_secret'],
    'default_graph_version' => 'v2.2',
]);

$helper = $fb->getRedirectLoginHelper();

try {
    $accessToken = $helper->getAccessToken();
} catch(Facebook\Exceptions\FacebookResponseException $e) {
    echo 'Graph returned an error: ' . $e->getMessage();
    exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
    echo 'Facebook SDK returned an error: ' . $e->getMessage();
    exit;
}

if (! isset($accessToken)) {
    if ($helper->getError()) {
        header('HTTP/1.0 401 Unauthorized');
        echo "Error: " . $helper->getError() . "\n";
        echo "Error Code: " . $helper->getErrorCode() . "\n";
        echo "Error Reason: " . $helper->getErrorReason() . "\n";
        echo "Error Description: " . $helper->getErrorDescription() . "\n";
    } else {
        header('HTTP/1.0 400 Bad Request');
        echo 'Bad request';
    }
    exit;
}

// Logged in
echo '<h3>Access Token</h3>';
var_dump($accessToken->getValue());

// The OAuth 2.0 client handler helps us manage access tokens
$oAuth2Client = $fb->getOAuth2Client();

// Get the access token metadata from /debug_token
$tokenMetadata = $oAuth2Client->debugToken($accessToken);
echo '<h3>Metadata</h3>';
var_dump($tokenMetadata);

// Validation (these will throw FacebookSDKException's when they fail)
$tokenMetadata->validateAppId($config['facebook']['app_id']); // Replace {app-id} with your app id
// If you know the user ID this access token belongs to, you can validate it here
//$tokenMetadata->validateUserId('123');
$tokenMetadata->validateExpiration();

if (! $accessToken->isLongLived()) {
    // Exchanges a short-lived access token for a long-lived one
    try {
        $accessToken = $oAuth2Client->getLongLivedAccessToken($accessToken);
    } catch (Facebook\Exceptions\FacebookSDKException $e) {
        echo "<p>Error getting long-lived access token: " . $helper->getMessage() . "</p>\n\n";
        exit;
    }

    echo '<h3>Long-lived</h3>';
    var_dump($accessToken->getValue());
}

$_SESSION['fb_access_token'] = (string) $accessToken;

try {
    // Returns a `Facebook\FacebookResponse` object
    // EXAMPLE: /me?fields=id,name
    $response = $fb->get('/me?fields=id,name,email', (string) $accessToken);
} catch(Facebook\Exceptions\FacebookResponseException $e) {
    echo 'Graph returned an error: ' . $e->getMessage();
    exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
    echo 'Facebook SDK returned an error: ' . $e->getMessage();
    exit;
}

$user = $response->getGraphUser();

echo 'Name: ' . $user['name'];
echo 'email: ' .$user['email'];

Fluid Iterator + Modulo

<f:for each="{example.collection}" as="item"  iteration="iterator"  >
   <f:if condition="{iterator.index} % 2">
     <f:then>Rest</f:then>
      <f:else>
          <f:if condition="{iterator.index}==0">
              <f:then>First</f:then>
              <f:else>kein Rest</f:else>
          </f:if>
      </f:else>
   </f:if>
</f:for>

Widget->PaginateViewHelper

plugin.tx_infochy_example{
    view {
        widget {
            TYPO3\CMS\Fluid\ViewHelpers\Widget\PaginateViewHelper {
                templateRootPath = {$plugin.tx_infochy_example.view.templateRootPath}
            }
        }
    }
}

RealURL Autoconf

https://docs.typo3.org/typo3cms/extensions/realurl/Realurl/AutomaticConfiguration/AutomaticConfigurationOfExtensions/Index.html

ext_localconf.php

$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/realurl/class.tx_realurl_autoconfgen.php']['extensionConfiguration'][$_EXTKEY] = 
'EXT:' . $_EXTKEY . '/Classes/Hooks/RealurlAutoconf.php:Infochy\\InfochyExample\\Hooks\\RealurlAutoconf->pluginConfiguration';

HOOK

class RealurlAutoconf {

    /**
     * @param array $params
     * @param \DmitryDulepov\Realurl\Configuration\AutomaticConfigurator $pObj
     * @return array
     */
    public function pluginConfiguration($params, &$pObj) {
        return array_merge_recursive($params['config'], array(
                'postVarSets' => array(
                    '_DEFAULT' => array(
                        'plugin' => array(
                            array(
                                'GETvar' => 'tx_infochy_example[action]',
                                'valueMap' => array(
                                    'show' => 'show',
                                    'list' => 'list',
                                ),
                                'noMatch' => 'bypass',
                            ),
                            array(
                                'GETvar' => 'tx_infochy_example[controller]',
                                'valueMap' => array(
                                    'Example' => 'controller',
                                ),
                                'noMatch' => 'bypass',
                            ),
                            array(
                                'GETvar' => 'tx_infochy_example[item]',
                                'lookUpTable' => array(
                                    'table' => 'tx_infochy_domain_model_example',
                                    'id_field' => 'uid',
                                    'alias_field' => 'title',
                                    'useUniqueCache' => 1,
                                    'useUniqueCache_conf' => array(
                                        'strtolower' => 1,
                                        'spaceCharacter' => '-',
                                    ),
                                ),
                            ),
                        ),
                        'paginate' => array(
                            array(
                                'GETvar' => 'tx_infochy_example[@widget_0][currentPage]',
                                //'noMatch' => 'bypass',
                            ),
                            array(
                                'GETvar' => 'tx_infochy_example[action]',
                                'valueMap' => array(
                                    'show' => 'show',
                                    'list' => 'list',
                                ),
                                'noMatch' => 'bypass',
                            ),
                            array(
                                'GETvar' => 'tx_infochy_example[controller]',
                                'valueMap' => array(
                                    'Example' => 'controller',
                                ),
                                'noMatch' => 'bypass',
                            ),
                        ),

                    ),
                ),
            )
        );
    }


}

Simple jQuery Slider

https://github.com/wallpageNET/jquery_example/tree/master/slider

$(document).ready(() => {  
	let slideCount = $('#slider ul li').length;
	let slideWidth = $('#slider ul li').width();
	let slideHeight = $('#slider ul li').height();
	let sliderUlWidth = slideCount * slideWidth; 
	$('#slider ul').css({ width: sliderUlWidth, marginLeft: - slideWidth });
	$('#slider ul li:last-child').prependTo('#slider ul');
	$('a.right').on('click',(e) => { 
		$('#slider ul').animate({
		    left: + slideWidth
		}, 500, () => {
		    $('#slider ul li:last-child').prependTo('#slider ul');
		    $('#slider ul').css('left', '');
		});
	});
	$('a.left').on('click',(e) => { 
		$('#slider ul').animate({
		    left: - slideWidth
		}, 500, () => {
		    $('#slider ul li:first-child').appendTo('#slider ul');
		    $('#slider ul').css('left', '');
		});
        });
});

jQuery scrolling fixen

$(() => {
$('a').on('click', (event) => {
  var $anchor = $(this);
  if($anchor.attr('href').substr(0, 9)==='#section_'){
    $('html, body').stop().animate({
      scrollTop: ($($anchor.attr('href')).offset().top - 150)
    }, 1250, 'easeInOutExpo');
   }
});
});

Fluid – News Artikel der letzten 5 Tage mit UPDATE oder NEW makieren

// Datum des Artikels: {newsItem.datetime}
// Datum der letzten Artikel Bearbeitung: {newsItem.tstamp}
// Datensatz wurde erzeugt am: {newsItem.crdate}

NEW

<f:if condition="{f:format.date(date: newsItem.datetime, format: 'Y-m-d')} > {f:format.date(date: '-5 days' format: 'Y-m-d')}">
NEW
</f:if>

UPDATE

<f:if condition="{f:format.date(date: newsItem.tstamp, format: 'Y-m-d')} > {f:format.date(date: '-5 days' format: 'Y-m-d')}">
UPDATE
</f:if>