Commit fb873ea9 authored by taras's avatar taras
Browse files

v1.0.0

parents
# Default ignored files
/shelf/
/workspace.xml
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/" isTestSource="false" packagePrefix="SapientPro\Core\" />
<sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/module-facebook.iml" filepath="$PROJECT_DIR$/.idea/module-facebook.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="PhpProjectSharedConfiguration" php_language_level="7" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
<?php
/**
* SapientPro
*
* @category SapientPro
* @package SapientPro_Core
* @author SapientPro Team <info@sapient.pro >
* @copyright Copyright © 2009-2019 SapientPro (https://sapient.pro)
*/
namespace SapientPro\Facebook\Api;
use \Magento\Framework\Notification\NotifierInterface;
use \Magento\Framework\Message\ManagerInterface;
/**
* Class Notify
* @package SapientPro\Core\Cron
*/
interface FacebookInterface
{
/**
* @return mixed
*/
public function getSdk() : \Facebook\Facebook;
}
Copyright (c) 2020 SapientPro (https://sapient.pro)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
<?php
/**
* SapientPro
*
* @category SapientPro
* @package SapientPro_Core
* @author SapientPro Team <info@sapient.pro >
* @copyright Copyright © 2009-2019 SapientPro (https://sapient.pro)
*/
namespace SapientPro\Facebook\Service;
use Exception;
use Facebook\Exceptions\FacebookSDKException;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Encryption\EncryptorInterface;
use Magento\Store\Model\ScopeInterface;
use SapientPro\Facebook\Api\FacebookInterface;
/**
* Class Notify
* @package SapientPro\Core\Cron
*/
class Facebook implements FacebookInterface
{
/**
* @var NotifierInterface
*/
private $sdk;
/**
* Facebook constructor.
* @param ScopeConfigInterface $scopeConfig
* @param EncryptorInterface $enCrypt
* @throws FacebookSDKException
*/
public function __construct(
ScopeConfigInterface $scopeConfig,
EncryptorInterface $enCrypt
) {
$this->sdk = new \Facebook\Facebook([
'app_id' => $scopeConfig->getValue(
'sapientpro/facebook/app_id',
ScopeInterface::SCOPE_STORE
),
'app_secret' => $enCrypt->decrypt(
$scopeConfig->getValue(
'sapientpro/facebook/app_secret',
ScopeInterface::SCOPE_STORE
)
)
]);
}
/**
* @return \Facebook\Facebook
* @throws Exception
*/
public function getSdk() : \Facebook\Facebook
{
if ($this->sdk instanceof \Facebook\Facebook) {
return $this->sdk;
}
throw new Exception();
}
}
<?php
/**
* SapientPro
*
* @category SapientPro
* @package SapientPro_Core
* @author SapientPro Team <info@sapient.pro >
* @copyright Copyright © 2009-2019 SapientPro (https://sapient.pro)
*/
namespace SapientPro\Facebook\ViewModel;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\DataObject;
use Magento\Framework\View\Element\Block\ArgumentInterface;
use \Magento\Framework\Locale\ResolverInterface as LocaleResolverInterface;
/**
* Class JavaScriptSDK
* @package SapientPro\Facebook\ViewModel
*/
class JavaScriptSDK extends DataObject implements ArgumentInterface
{
/**
* Current API version
*/
const API_VERSION = 'v6.0';
/**
* @var ScopeConfigInterface
*/
private $scopeConfig;
/**
* @var LocaleResolverInterface
*/
private $localeResolver;
/**
* @param ScopeConfigInterface $scopeConfig
* @param LocaleResolverInterface $localeResolver
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function __construct(
ScopeConfigInterface $scopeConfig,
LocaleResolverInterface $localeResolver
) {
$this->scopeConfig = $scopeConfig;
$this->localeResolver = $localeResolver;
}
/**
* @return string
*/
public function getVersion() : string
{
return self::API_VERSION;
}
/**
* @return mixed
*/
public function getAppId() : string
{
return $this->scopeConfig->getValue('sapientpro/facebook/app_id');
}
/**
* @return mixed
*/
public function getLocaleCode()
{
return $this->localeResolver->getLocale();
}
}
{
"name": "sapientpro/module-facebook",
"description": "SapientPro Facebook",
"type": "magento2-module",
"version": "1.0.0",
"license": [
"OSL-3.0",
"AFL-3.0"
],
"authors": [
{
"name": "SapientPro",
"email": "info@sapient.pro",
"homepage": "https://sapient.pro/"
}
],
"keywords": [
"magento 2",
"SapientPro",
"facebook"
],
"config": {
"sort-packages": true
},
"require": {
"php": ">=7.0",
"sapientpro/module-core": "*"
},
"autoload": {
"files": [
"registration.php"
],
"psr-4": {
"SapientPro\\Facebook\\": ""
}
}
}
<?xml version="1.0"?>
<!--
/**
* SapientPro
*
* @category SapientPro
* @package SapientPro_Instagram
* @author SapientPro Team <info@sapient.pro >
* @copyright Copyright © 2009-2019 SapientPro (https://sapient.pro)
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../Config/etc/system_file.xsd">
<system>
<section id="sapientpro" translate="label" type="text" sortOrder="200" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Social Networks</label>
<tab>sapient_pro_extension_tab</tab>
<resource>SapientPro_Facebook::configuration</resource>
<group id="facebook" translate="label" type="select" sortOrder="200" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Facebook</label>
<field id="active" translate="label" type="select" sortOrder="100" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Enable</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<comment>Select Mode</comment>
</field>
<field id="app_id" translate="label comment" type="text" sortOrder="200" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Facebook application ID</label>
<comment><![CDATA[You can create your facebook application <a target="_blank" href="https://developers.facebook.com/apps/">here</a>]]></comment>
<depends>
<field id="active" separator=",">1</field>
</depends>
<validate>required-entry</validate>
</field>
<field id="app_secret" translate="label comment" type="obscure" sortOrder="300" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Facebook application secret</label>
<comment><![CDATA[You can create your facebook application <a target="_blank" href="https://developers.facebook.com/apps/">here</a>]]></comment>
<depends>
<field id="active" separator=",">1</field>
</depends>
<backend_model>Magento\Config\Model\Config\Backend\Encrypted</backend_model>
<validate>required-entry</validate>
</field>
</group>
</section>
</system>
</config>
<?xml version="1.0"?>
<!--
/**
* SapientPro
*
* @category SapientPro
* @package SapientPro_Instagram
* @author SapientPro Team <info@sapient.pro >
* @copyright Copyright © 2009-2019 SapientPro (https://sapient.pro)
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="SapientPro\Facebook\Service\FacebookInterface" type="SapientPro\Facebook\Service\Facebook" />
</config>
<?xml version="1.0"?>
<!--
/**
* SapientPro
*
* @category SapientPro
* @package SapientPro_Instagram
* @author SapientPro Team <info@sapient.pro >
* @copyright Copyright © 2009-2019 SapientPro (https://sapient.pro)
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
<module name="SapientPro_Facebook" setup_version="1.0.0">
<sequence>
<module name="SapientPro_Core"/>
</sequence>
</module>
</config>
<?php
/**
* SapientPro
*
* @category SapientPro
* @package SapientPro_Instagram
* @author SapientPro Team <info@sapient.pro >
* @copyright Copyright © 2009-2019 SapientPro (https://sapient.pro)
*/
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'SapientPro_Facebook',
__DIR__
);
\ No newline at end of file
This diff is collapsed.
<?xml version="1.0"?>
<!--
/**
* SapientPro
*
* @category SapientPro
* @package SapientPro_Instagram
* @author SapientPro Team <info@sapient.pro >
* @copyright Copyright © 2009-2019 SapientPro (https://sapient.pro)
*/
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-right"
xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="after.body.start">
<block name="sapientpro.facebook.javascript.sdk" template="SapientPro_Facebook::javascript-sdk.phtml"
ifconfig="sapientpro/facebook/active">
<arguments>
<argument name="javaScriptSDK" xsi:type="object">SapientPro\Facebook\ViewModel\JavaScriptSDK</argument>
<argument name="localeResolver" xsi:type="object">SapientPro\Core\ViewModel\Locale</argument>
</arguments>
</block>
</referenceContainer>
</body>
</page>
<?php
/**
* SapientPro
*
* @category SapientPro
* @package SapientPro_Instagram
* @author SapientPro Team <info@sapient.pro >
* @copyright Copyright © 2009-2019 SapientPro (https://sapient.pro)
*/
/** @var SapientPro\Facebook\ViewModel\JavaScriptSDK $javaScriptSDK */
$javaScriptSDK = $block->getData('javaScriptSDK');
/** @var SapientPro\Core\ViewModel\Locale $localeResolver */
$localeResolver = $block->getData('localeResolver');
?>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '<?= $javaScriptSDK->getAppId() ?>',
cookie : true,
xfbml : true,
version : '<?= $javaScriptSDK->getVersion() ?>'
});
FB.AppEvents.logPageView();
};
</script>
<script async defer src="https://connect.facebook.net/<?= $localeResolver->getLocaleCode() ?>/sdk.js"></script>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment