Skip to content

Commit

Permalink
ver 1.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
norbert-feria-53 committed Jul 27, 2017
1 parent d812a28 commit 4907c39
Show file tree
Hide file tree
Showing 7 changed files with 490 additions and 19 deletions.
34 changes: 33 additions & 1 deletion app/code/Tawk/Widget/Block/Adminhtml/SelectWidgetBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
class SelectWidgetBlock extends Template
{
const BASE_URL = 'https://plugins.tawk.to';
protected $logger;
protected $logger;
protected $modelWidgetFactory;

public function __construct(Template\Context $context, WidgetFactory $modelFactory, array $data = [])
Expand All @@ -34,18 +34,46 @@ public function __construct(Template\Context $context, WidgetFactory $modelFacto
$this->modelWidgetFactory = $modelFactory;
}

function mainurl(){
if(isset($_SERVER['HTTPS'])){
$protocol = ($_SERVER['HTTPS'] && $_SERVER['HTTPS'] != "off") ? "https" : "http";
}
else{
$protocol = 'http';
}
return $protocol . "://" . $_SERVER['HTTP_HOST'];
}

public function getWebSiteoptions(){
$sdstr = '';

$websites = $this->_storeManager->getWebsites();
#$sdstr .= '<option value="0">Select Store</option>';
foreach ($websites as $website) {
$sdstr .= '<option value="'.$website->getId().'">'.$website->getName().'</option>';
}
return $sdstr;
}

public function _prepareLayout()
{
return parent::_prepareLayout();
}

public function getIframeUrl()
{
/*
return $this->getBaseUrl()
.'/generic/widgets'
.'?parentDomain='.$this->_storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_WEB)
.'&selectType=singleIdSelect'
.'&selectText=Store';
*/

return $this->getBaseUrl().'/generic/widgets'
.'?currentWidgetId=&currentPageId=&transparentBackground=1'
.'&parentDomain='.$this->mainurl();

}

public function getBaseUrl() {
Expand Down Expand Up @@ -90,6 +118,10 @@ public function getRemoveUrl() {
return $this->getUrl('widget/removewidget', ['_secure' => true]);
}

public function getStoreWidget(){
return $this->getUrl('widget/storewidget', ['_secure' => true]);
}

private function parseGroups($groups) {
$return = array();

Expand Down
77 changes: 76 additions & 1 deletion app/code/Tawk/Widget/Block/Embed.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,81 @@ protected function _toHtml()
return '';
}

return parent::_toHtml();
$alwaysdisplay = $this->model->getAlwaysDisplay();
$donotdisplay = $this->model->getDoNotDisplay();
$display = true;

if($alwaysdisplay == 1){
$display = true;

$excluded_url_list = $this->model->getExcludeUrl();

if(strlen( $excluded_url_list ) > 0 )
{
$current_url = $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];
$current_url = urldecode($current_url);

$ssl = ( ! empty( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] == 'on' );
$sp = strtolower( $_SERVER['SERVER_PROTOCOL'] );
$protocol = substr( $sp, 0, strpos( $sp, '/' ) ) . ( ( $ssl ) ? 's' : '' );

$current_url = $protocol.'://'.$current_url;
$current_url = strtolower($current_url);

#$exclude_url = trim( strtolower( $this->model->getExcludeUrl() ) );
$current_url = trim( strtolower( $current_url ) );


$excluded_url_list = preg_split("/,/", $excluded_url_list);

foreach($excluded_url_list as $exclude_url)
{
$exclude_url = strtolower(urldecode(trim($exclude_url)));
if (strpos($current_url, $exclude_url) !== false)
{
$display = false;
}
}
}
}else{
$display = false;
}


if($donotdisplay == 1){
$display = false;

$included_url_list = $this->model->getIncludeUrl();
if(strlen( $included_url_list ) > 0 )
{
$current_url = $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];
$current_url = urldecode($current_url);

$ssl = ( ! empty( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] == 'on' );
$sp = strtolower( $_SERVER['SERVER_PROTOCOL'] );
$protocol = substr( $sp, 0, strpos( $sp, '/' ) ) . ( ( $ssl ) ? 's' : '' );

$current_url = $protocol.'://'.$current_url;
$current_url = strtolower($current_url);

$current_url = trim( strtolower( $current_url ) );

$included_url_list = preg_split("/,/", $included_url_list);
foreach($included_url_list as $include_url)
{
$exclude_url = strtolower(urldecode(trim($include_url)));
if (strpos($current_url, $include_url) !== false)
{
$display = true;
}
}
}
}

if($display == true){
return parent::_toHtml();
}else{
return '';
}
}
}
16 changes: 11 additions & 5 deletions app/code/Tawk/Widget/Controller/Adminhtml/SaveWidget/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,19 @@ public function execute()
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$model = $objectManager->get('Tawk\Widget\Model\Widget')->loadByForStoreId(filter_input(INPUT_POST, 'id', FILTER_SANITIZE_STRING));

if(!$model->hasId()) {
$model = $objectManager->get('Tawk\Widget\Model\Widget');
if( ($_POST['pageId'] == '-1') && ($_POST['widgetId'] == '-1') ){

}else{
$model->setPageId(filter_input(INPUT_POST, 'pageId', FILTER_SANITIZE_STRING));
$model->setWidgetId(filter_input(INPUT_POST, 'widgetId', FILTER_SANITIZE_STRING));
}
$model->setForStoreId($_POST['id']);

$model->setAlwaysDisplay($_POST['alwaysdisplay']);
$model->setExcludeUrl($_POST['excludeurl']);

$model->setPageId(filter_input(INPUT_POST, 'pageId', FILTER_SANITIZE_STRING));
$model->setWidgetId(filter_input(INPUT_POST, 'widgetId', FILTER_SANITIZE_STRING));
$model->setForStoreId(filter_input(INPUT_POST, 'id', FILTER_SANITIZE_STRING));
$model->setDoNotDisplay($_POST['donotdisplay']);
$model->setIncludeUrl($_POST['includeurl']);

$model->save();

Expand Down
61 changes: 61 additions & 0 deletions app/code/Tawk/Widget/Controller/Adminhtml/StoreWidget/Index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php
/**
* Tawk.to
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* @copyright Copyright (c) 2016 Tawk.to
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

namespace Tawk\Widget\Controller\Adminhtml\StoreWidget;

use Magento\Framework\Controller\Result\JsonFactory;
use Magento\Backend\App\Action\Context;
use Psr\Log\LoggerInterface;

class Index extends \Magento\Backend\App\Action
{
protected $resultJsonFactory;
protected $logger;

public function __construct(Context $context, JsonFactory $resultJsonFactory, LoggerInterface $logger)
{
parent::__construct($context);
$this->resultJsonFactory = $resultJsonFactory;
$this->logger = $logger;
}

public function execute()
{
$response = $this->resultJsonFactory->create();
$response->setHeader('Content-type', 'application/json');

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$model = $objectManager->get('Tawk\Widget\Model\Widget')->loadByForStoreId(filter_input(INPUT_GET, 'id', FILTER_SANITIZE_STRING));

if(!$model->hasId()) {
$model = $objectManager->get('Tawk\Widget\Model\Widget');
}

$pageId = $model->getPageId();
$widgetId = $model->getWidgetId();


$alwaysdisplay = $model->getAlwaysDisplay();
$excludeurl = $model->getExcludeUrl();

$donotdisplay = $model->getDoNotDisplay();
$includeurl = $model->getIncludeUrl();

return $response->setData(['success' => TRUE,'pageid' => $pageId,'widgetid' => $widgetId,'alwaysdisplay' => $alwaysdisplay,'excludeurl' => $excludeurl,'donotdisplay' => $donotdisplay,'includeurl' => $includeurl]);
}
}
24 changes: 24 additions & 0 deletions app/code/Tawk/Widget/Setup/InstallSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,30 @@ public function install(SchemaSetupInterface $setup, ModuleContextInterface $con
50,
[],
'Widget Id'
)->addColumn(
'always_display',
Table::TYPE_INTEGER,
1,
[],
'always_display'
)->addColumn(
'exclude_url',
Table::TYPE_TEXT,
255,
[],
'exclude_url'
)->addColumn(
'do_not_display',
Table::TYPE_INTEGER,
1,
[],
'do_not_display'
)->addColumn(
'include_url',
Table::TYPE_TEXT,
255,
[],
'include_url'
)->setComment(
'Tawk Widget table that makes connection between stores and widgets'
);
Expand Down
4 changes: 2 additions & 2 deletions app/code/Tawk/Widget/etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@
-->

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Tawk_Widget" setup_version="1.0.0"/>
</config>
<module name="Tawk_Widget" setup_version="1.3.1"/>
</config>
Loading

0 comments on commit 4907c39

Please sign in to comment.