Skip to content

Commit

Permalink
updated
Browse files Browse the repository at this point in the history
  • Loading branch information
ecomteck committed Aug 22, 2019
1 parent 24c588a commit b1d188e
Show file tree
Hide file tree
Showing 11 changed files with 158 additions and 31 deletions.
10 changes: 3 additions & 7 deletions Block/Adminhtml/Widget/Form/Field/WysiwygEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,9 @@ public function render(AbstractElement $element){

$html .= <<<HTML
<script>
window.tinyMCE_GZ = window.tinyMCE_GZ || {}; window.tinyMCE_GZ.loaded = true;
require([
"jquery",
"mage/translate",
"mage/adminhtml/events",
"mage/adminhtml/wysiwyg/tiny_mce/setup",
"mage/adminhtml/wysiwyg/widget"
'jquery',
'Ves_Productlist/js/wysiwyg/tiny_mce/setup'
], function(jQuery){
var config = $config,
editor;
Expand All @@ -145,7 +141,7 @@ public function render(AbstractElement $element){
config
);
editor{$element->getHtmlId()}.toggle();
editor{$element->getHtmlId()}.turnOn();
varienGlobalEvents.clearEventHandlers("open_browser_callback");
varienGlobalEvents.attachEventHandler("open_browser_callback", editor{$element->getHtmlId()}.openFileBrowser);
jQuery('#{$element->getHtmlId()}')
Expand Down
24 changes: 19 additions & 5 deletions Controller/Widget/Adminhtml/Widget/BuildWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,23 @@ public function execute()
$this->getResponse()->setBody($html);
}
public function isBase64Encoded($data) {
if(base64_encode(base64_decode($data)) === $data){
return true;
}
return false;
}
if(base64_encode($data) === $data) return false;
if(base64_encode(base64_decode($data)) === $data){
return true;
}
if (!preg_match('~[^0-9a-zA-Z+/=]~', $data)) {
$check = str_split(base64_decode($data));
$x = 0;
foreach ($check as $char) if (ord($char) > 126) $x++;
if ($x/count($check)*100 < 30) return true;
}
$decoded = base64_decode($data);
// Check if there are valid base64 characters
if (!preg_match('/^[a-zA-Z0-9\/\r\n+]*={0,2}$/', $data)) return false;
// if string returned contains not printable chars
if (0 < preg_match('/((?![[:graph:]])(?!\s)(?!\p{L}))./', $decoded, $matched)) return false;
if (!preg_match('%^[a-zA-Z0-9/+]*={0,2}$%', $data)) return false;

return false;
}
}
24 changes: 19 additions & 5 deletions Model/Magento/Widget/Instance.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,23 @@ public function getWidgetParameters()
return parent::getWidgetParameters();
}
public function isBase64Encoded($data) {
if(base64_encode(base64_decode($data)) === $data){
return true;
}
return false;
}
if(base64_encode($data) === $data) return false;
if(base64_encode(base64_decode($data)) === $data){
return true;
}
if (!preg_match('~[^0-9a-zA-Z+/=]~', $data)) {
$check = str_split(base64_decode($data));
$x = 0;
foreach ($check as $char) if (ord($char) > 126) $x++;
if ($x/count($check)*100 < 30) return true;
}
$decoded = base64_decode($data);
// Check if there are valid base64 characters
if (!preg_match('/^[a-zA-Z0-9\/\r\n+]*={0,2}$/', $data)) return false;
// if string returned contains not printable chars
if (0 < preg_match('/((?![[:graph:]])(?!\s)(?!\p{L}))./', $decoded, $matched)) return false;
if (!preg_match('%^[a-zA-Z0-9/+]*={0,2}$%', $data)) return false;

return false;
}
}
40 changes: 37 additions & 3 deletions Model/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class Product extends \Magento\Framework\DataObject
*/
protected $_reportCollection;

protected $_vesreportCollection;

/**
* @var \Magento\Catalog\Model\Product\Visibility
*/
Expand Down Expand Up @@ -78,7 +80,8 @@ class Product extends \Magento\Framework\DataObject

/**
* @param \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory
* @param \Magento\Reports\Model\ResourceModel\Product\CollectionFactory $reportCollection
* @param \Magento\Reports\Model\ResourceModel\Product\CollectionFactory $reportCollection
* @param \Ves\Productlist\Model\ResourceModel\Reports\Product\CollectionFactory $vesreportCollection
* @param \Magento\Catalog\Model\Product\Visibility $catalogProductVisibility
* @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
Expand All @@ -93,6 +96,7 @@ class Product extends \Magento\Framework\DataObject
public function __construct(
\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory,
\Magento\Reports\Model\ResourceModel\Product\CollectionFactory $reportCollection,
\Ves\Productlist\Model\ResourceModel\Reports\Product\CollectionFactory $vesreportCollection,
\Magento\Catalog\Model\Product\Visibility $catalogProductVisibility,
\Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate,
\Magento\Store\Model\StoreManagerInterface $storeManager,
Expand All @@ -107,6 +111,7 @@ public function __construct(
$this->_localeDate = $localeDate;
$this->_productCollectionFactory = $productCollectionFactory;
$this->_reportCollection = $reportCollection;
$this->_vesreportCollection = $vesreportCollection;
$this->_catalogProductVisibility = $catalogProductVisibility;
$this->_storeManager = $storeManager;
$this->date = $date;
Expand Down Expand Up @@ -492,15 +497,44 @@ public function getDealsProducts($config = [])
return $collection;
}

public function getInterval(){
$interval = $this->getData("interval");
if(!$interval) {
$interval = 45;
}
return (int)$interval;
}
/**
* Retrieve From To Interval
*
* @return array
*/
public function getFromTo()
{
$from = '';
$to = '';
$interval = (int)$this->getInterval();

if ($interval > 0) {
$dtTo = new \DateTime();
$dtFrom = clone $dtTo;
// last $interval day(s)
$dtFrom->modify("-{$interval} day");
$from = $dtFrom->format('Y-m-d');
$to = $dtTo->format('Y-m-d');
}
return [$from, $to];
}
/**
* Most viewed product collection
*
* @return \Magento\Catalog\Model\ResourceModel\Product\Collection|Object|\Magento\Framework\Data\Collection
*/
public function getMostViewedProducts($config = [])
{
/** @var $collection \Magento\Reports\Model\ResourceModel\Product\CollectionFactory */
$collection = $this->_reportCollection->create()->addAttributeToSelect('*')->addViewsCount();
list($from, $to) = $this->getFromTo();
/** @var $collection \Ves\Productlist\Model\ResourceModel\Reports\Product\CollectionFactory */
$collection = $this->_vesreportCollection->create()->addAttributeToSelect('*')->addViewsCount($from, $to);
if (isset($config['categories'])) {
if ($this->productState->isFlatEnabled()) {
$collection->joinField(
Expand Down
69 changes: 69 additions & 0 deletions Model/ResourceModel/Reports/Product/Collection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php
/**
* Venustheme
*
* NOTICE OF LICENSE
*
* This source file is subject to the Venustheme.com license that is
* available through the world-wide-web at this URL:
* http://www.venustheme.com/license-agreement.html
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this extension to newer
* version in the future.
*
* @category Venustheme
* @package Ves_Productlist
* @copyright Copyright (c) 2014 Venustheme (http://www.venustheme.com/)
* @license http://www.venustheme.com/LICENSE-1.0.html
*/
namespace Ves\Productlist\Model\ResourceModel\Reports\Product;
use Magento\Reports\Model\ResourceModel\Product\Collection as ProductCollection;
/**
* Product Most Viewed Collection
*/
class Collection extends ProductCollection
{
/**
* Add Views Count
*
* @param string $from
* @param string $to
* @return \Ves\Productlist\Model\ResourceModel\Reports\Product\Collection
*/
public function addViewsCount($from='', $to='')
{
/**
* Getting event type id for catalog_product_view event
*/
$eventTypes = $this->_eventTypeFactory->create()->getCollection();
foreach ($eventTypes as $eventType) {
if ($eventType->getEventName() == 'catalog_product_view') {
$productViewEvent = (int)$eventType->getId();
break;
}
}
$this->getSelect()->reset()->from(
['report_table_views' => $this->getTable('report_event')],
['views' => 'COUNT(report_table_views.event_id)']
)->join(
['e' => $this->getProductEntityTableName()],
'e.entity_id = report_table_views.object_id'
)->where(
'report_table_views.event_type_id = ?',
$productViewEvent
)->group(
'e.entity_id'
)->order(
'views ' . self::SORT_ORDER_DESC
)->having(
'COUNT(report_table_views.event_id) > ?',
0
);
if ($from != '' && $to != '') {
$this->getSelect()->where('logged_at >= ?', $from)->where('logged_at <= ?', $to);
}
return $this;
}
}
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
"name": "venustheme/magento2-product-list",
"description": "Venustheme Magento 2 Product List supports you to create a wanted list of products based on attribute, types, conditions of items.",
"require": {
"venustheme/magento2-all": "1.*"
"venustheme/module-all": "1.*"
},
"type": "magento2-module",
"version": "1.0.0",
"keywords": [
"landofcoder",
"landofcoder product list",
"venustheme",
"venustheme product list",
"product list magento 2",
"magento 2 product list",
"product list magento 2",
Expand All @@ -20,8 +20,8 @@
],
"authors": [
{
"name": "Landofcoder",
"email": "landofcoder@gmail.com",
"name": "Venustheme",
"email": "venustheme@gmail.com",
"role": "Magento 2 Ves Product List"
}
],
Expand Down
4 changes: 2 additions & 2 deletions view/adminhtml/templates/wysiwyg/js.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
require([
"jquery",
"tinymce",
"wysiwygAdapter",
"prototype",
"mage/adminhtml/events"
], function(jQuery, tinyMCE){

Expand Down Expand Up @@ -73,7 +73,7 @@ var productlistWysiwygEditor = {
okDialogWindow : function(dialogWindow) {
if (dialogWindow.options.firedElementId) {
wysiwygObj = eval('wysiwyg'+dialogWindow.options.firedElementId+'_editor');
wysiwygObj.toggle();
wysiwygObj.turnOff();
if (tinyMCE.get(wysiwygObj.id)) {
$(dialogWindow.options.firedElementId).value = tinyMCE.get(wysiwygObj.id).getContent();
} else {
Expand Down
2 changes: 1 addition & 1 deletion view/adminhtml/templates/wysiwyg/wysiwyg/tiny_mce/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
define([
'jquery',
'underscore',
'wysiwygAdapter',
'tinymce',
'mage/translate',
'prototype',
'mage/adminhtml/events',
Expand Down
2 changes: 1 addition & 1 deletion view/adminhtml/templates/wysiwyg/wysiwyg/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

define([
"jquery",
"wysiwygAdapter",
"tinymce",
'Magento_Ui/js/modal/alert',
"jquery/ui",
"mage/translate",
Expand Down
2 changes: 1 addition & 1 deletion view/adminhtml/web/js/vesbrowser.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*jshint browser:true jquery:true*/
define([
"jquery",
"wysiwygAdapter",
"tinymce",
"Magento_Ui/js/modal/prompt",
"Magento_Ui/js/modal/confirm",
"Magento_Ui/js/modal/alert",
Expand Down
2 changes: 1 addition & 1 deletion view/adminhtml/web/js/wysiwyg/tiny_mce/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
define([
'jquery',
'underscore',
'wysiwygAdapter',
'tinymce',
'mage/translate',
'prototype',
'mage/adminhtml/events',
Expand Down

0 comments on commit b1d188e

Please sign in to comment.