From 4907c399e74d388111640f7d2b84c1c12ec88028 Mon Sep 17 00:00:00 2001 From: norbert-feria-53 Date: Thu, 27 Jul 2017 18:52:06 +0800 Subject: [PATCH] ver 1.3.1 --- .../Block/Adminhtml/SelectWidgetBlock.php | 34 +- app/code/Tawk/Widget/Block/Embed.php | 77 ++++- .../Controller/Adminhtml/SaveWidget/Index.php | 16 +- .../Adminhtml/StoreWidget/Index.php | 61 ++++ app/code/Tawk/Widget/Setup/InstallSchema.php | 24 ++ app/code/Tawk/Widget/etc/module.xml | 4 +- .../adminhtml/templates/selectwidget.phtml | 293 +++++++++++++++++- 7 files changed, 490 insertions(+), 19 deletions(-) create mode 100755 app/code/Tawk/Widget/Controller/Adminhtml/StoreWidget/Index.php diff --git a/app/code/Tawk/Widget/Block/Adminhtml/SelectWidgetBlock.php b/app/code/Tawk/Widget/Block/Adminhtml/SelectWidgetBlock.php index d14d90a..6ed479f 100755 --- a/app/code/Tawk/Widget/Block/Adminhtml/SelectWidgetBlock.php +++ b/app/code/Tawk/Widget/Block/Adminhtml/SelectWidgetBlock.php @@ -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 = []) @@ -34,6 +34,27 @@ 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 .= ''; + foreach ($websites as $website) { + $sdstr .= ''; + } + return $sdstr; + } + public function _prepareLayout() { return parent::_prepareLayout(); @@ -41,11 +62,18 @@ public function _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=¤tPageId=&transparentBackground=1' + .'&parentDomain='.$this->mainurl(); + } public function getBaseUrl() { @@ -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(); diff --git a/app/code/Tawk/Widget/Block/Embed.php b/app/code/Tawk/Widget/Block/Embed.php index a8da4a0..2456a01 100755 --- a/app/code/Tawk/Widget/Block/Embed.php +++ b/app/code/Tawk/Widget/Block/Embed.php @@ -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 ''; + } } } \ No newline at end of file diff --git a/app/code/Tawk/Widget/Controller/Adminhtml/SaveWidget/Index.php b/app/code/Tawk/Widget/Controller/Adminhtml/SaveWidget/Index.php index 2fd2950..1d786b9 100755 --- a/app/code/Tawk/Widget/Controller/Adminhtml/SaveWidget/Index.php +++ b/app/code/Tawk/Widget/Controller/Adminhtml/SaveWidget/Index.php @@ -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(); diff --git a/app/code/Tawk/Widget/Controller/Adminhtml/StoreWidget/Index.php b/app/code/Tawk/Widget/Controller/Adminhtml/StoreWidget/Index.php new file mode 100755 index 0000000..d698d55 --- /dev/null +++ b/app/code/Tawk/Widget/Controller/Adminhtml/StoreWidget/Index.php @@ -0,0 +1,61 @@ +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]); + } +} \ No newline at end of file diff --git a/app/code/Tawk/Widget/Setup/InstallSchema.php b/app/code/Tawk/Widget/Setup/InstallSchema.php index 4c6b700..2b93e06 100755 --- a/app/code/Tawk/Widget/Setup/InstallSchema.php +++ b/app/code/Tawk/Widget/Setup/InstallSchema.php @@ -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' ); diff --git a/app/code/Tawk/Widget/etc/module.xml b/app/code/Tawk/Widget/etc/module.xml index 32fac61..fe97efd 100755 --- a/app/code/Tawk/Widget/etc/module.xml +++ b/app/code/Tawk/Widget/etc/module.xml @@ -20,5 +20,5 @@ --> - - \ No newline at end of file + + diff --git a/app/code/Tawk/Widget/view/adminhtml/templates/selectwidget.phtml b/app/code/Tawk/Widget/view/adminhtml/templates/selectwidget.phtml index 43b6cf4..e1cba67 100755 --- a/app/code/Tawk/Widget/view/adminhtml/templates/selectwidget.phtml +++ b/app/code/Tawk/Widget/view/adminhtml/templates/selectwidget.phtml @@ -16,15 +16,166 @@ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ ?> + + + + \ No newline at end of file + + +
+

Visibility Options

+
+ + +
+
+ +
+ +
+
+ + +
+
+ +
+ +
+ +
\ No newline at end of file