Skip to content

Commit

Permalink
add module files
Browse files Browse the repository at this point in the history
  • Loading branch information
ecomteck committed Aug 3, 2019
0 parents commit 76659f3
Show file tree
Hide file tree
Showing 137 changed files with 49,736 additions and 0 deletions.
39 changes: 39 additions & 0 deletions Block/Adminhtml/License.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
/**
* Landofcoder.com
*
* NOTICE OF LICENSE
*
* This source file is subject to the Landofcoder.com.com license that is
* available through the world-wide-web at this URL:
* https://www.landofcoder.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 Landofcoder.com
* @package Lof_All
* @copyright Copyright (c) 2016 Landofcoder.com (https://www.landofcoder.com/)
* @license https://www.landofcoder.com/LICENSE-1.0.html
*/
namespace Lof\All\Block\Adminhtml;

class License extends \Magento\Framework\View\Element\Template
{
protected function _toHtml() {
$extension = $this->getData('extension');
if ($extension) {
$this->_eventManager->dispatch(
'lof_check_license',
['obj' => $this,'ex'=>$extension]
);
$extension = str_replace("_", " ", $extension);
if (!$this->getData('is_valid')) {
return '<div style="margin-top: 5px;"><div class="messages error"><div class="message message-error" style="margin-bottom: 0;"><div>Module <b>' . $extension . '</b> is not yet registered! Go to <b>Backend > Landofcoder > Licenses</b> to register the module. Please login to your account in <a target="_blank" href="https://landofcoder.com">landofcoder.com</a>, then go to <b>Dashboard > My Downloadable Products</b>, enter your domains to get a new license. Next go to <b>Backend > Landofcoder > Licenses</b> to save the license.</div></div></div></div>';
}
}
return parent::_toHtml();
}
}
397 changes: 397 additions & 0 deletions Block/Adminhtml/System/ListLicense.php

Large diffs are not rendered by default.

182 changes: 182 additions & 0 deletions Block/Adminhtml/System/Market.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
<?php
/**
* Landofcoder
*
* 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://landofcoder.com/license
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this extension to newer
* version in the future.
*
* @category Landofcoder
* @package Lof_All
* @copyright Copyright (c) 2017 Landofcoder (https://www.landofcoder.com/)
* @license https://www.landofcoder.com/LICENSE-1.0.html
*/

namespace Lof\All\Block\Adminhtml\System;

use Magento\Framework\App\Filesystem\DirectoryList;
use Lof\All\Block\Adminhtml\System\ListLicense;

class Market extends \Magento\Config\Block\System\Config\Form\Field
{

/**
* @var \Magento\Framework\App\ResourceConnection
*/
protected $_resource;

protected $_key_path;

/**
* [__construct description]
* @param \Magento\Backend\Block\Template\Context $context
* @param \Magento\Framework\App\ResourceConnection $resource
* @param \Lof\All\Helper\Data $helper
* @param \Magento\Framework\HTTP\PhpEnvironment\RemoteAddress $remoteAddress
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Framework\App\ResourceConnection $resource,
\Lof\All\Helper\Data $helper,
\Lof\All\Model\License $license,
\Magento\Framework\HTTP\PhpEnvironment\RemoteAddress $remoteAddress
)
{
parent::__construct($context);
$this->_resource = $resource;
$this->_helper = $helper;
$this->_remoteAddress = $remoteAddress;
$this->_license = $license;
}

/**
* Retrieve HTML markup for given form element
*
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
* @return string
*/
public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element)
{
/*
if (!extension_loaded('soap')) {
throw new \Magento\Framework\Webapi\Exception(
__('SOAP extension is not loaded.'),
0,
\Magento\Framework\Webapi\Exception::HTTP_INTERNAL_ERROR
);
}
$products = array();
try{
$opts = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false
)
);
$context = stream_context_create($opts);
$params = array('soap_version'=>SOAP_1_2,
'verifypeer' => false,
'verifyhost' => false,
'exceptions' => 1,
'stream_context'=>$context);
$proxy = new \SoapClient(ListLicense::API_URL, $params);
$sessionId = $proxy->login(ListLicense::API_USERNAME, ListLicense::API_PASSWORD);
$products = $proxy->call($sessionId, 'veslicense.productlist1');
} catch(SoapFault $e){
}*/
$list_products = $this->getProductList();
$products = isset($list_products['products'])?$list_products['products']:[];
$total = 12;
$column = 2;
$x = 0;
$html = '';
$html .= '<div id="lof-elist">';
$html .= '<h1><a href="https://landofcoder.com">Landofcoder.com - Opensource Marketplace for magento, opencart</a></h1>';
foreach ($products as $_product) {
if( $column == 1 || $x%$column == 0){
$html .= '<div class="erow">';
}
$class = '';
if( $column == 1 || ($x+1)%$column == 0 || $x == ($total-1) ) {
$class = ' last';
}

if ($_product['price']==0 || $_product['price']=="" ||$_product['price']=="0.00" || $_product['price']=="$0.00" || !$_product['price']) {
$price = 'FREE';
} else {
$price = $_product['price_currency'];
}

$html .= '<div class="extend-card ' . $class . '">';
$html .= '<div class="extend-card-top">';
$html .= '<div class="extend-card-image"><a href="' . $_product['purl'] . '" title="' . $_product['name'] . '"><img src="' . $_product['pimg'] . '" class="plugin-icon" alt=""></a></div>';
$html .= '<div class="extend-card-desc"><a href="' . $_product['purl'] . '" title="' . $_product['name'] . '"><h3>' . $_product['name'] . '</h3></a><div class="extend-price">' . $price . '</div></div><div class="extend-des"> <div class="extend-des-inner"> ' . $_product['short_description'] . '</div> <a href="' . $_product['purl'] . '" title="' . $_product['name'] . '" class="extend-buynow" style="float: left;">Buy Now</a></div>';
$html .= '</div>';
$html .= '</div>';
if( $column == 1 || ($x+1)%$column == 0 || $x == ($total-1) ) {
$html .= '</div>';
}
$x++;
}
$html .= '</div>';

return $this->_decorateRowHtml($element, $html);
}
public function getProductList() {
//Authentication rest API magento2, get access token
$url = ListLicense::getListUrl();
$key_path = $this->getKeyPath();
$data = array();
$crl = curl_init();
curl_setopt($crl, CURLOPT_SSL_VERIFYPEER, TRUE);
curl_setopt($crl, CURLOPT_CAPATH, $key_path);
curl_setopt($crl, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($crl, CURLOPT_URL, $url);
curl_setopt($crl, CURLOPT_HEADER, 0);
curl_setopt($crl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($crl, CURLOPT_POST, 1);
curl_setopt($crl, CURLOPT_POSTFIELDS, $data);
$response = curl_exec($crl);
if ($response) {
}
else {
echo 'An error has occurred: ' . curl_error($crl);
return[];
}
curl_close($crl);

return json_decode($response, true);
}

public function getKeyPath(){
if(!$this->_key_path){
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$directory = $objectManager->get('\Magento\Framework\Filesystem\DirectoryList');
$base_url = $directory->getRoot();
$this->_key_path = $base_url."/veslicense/cacert.pem";
}
return $this->_key_path;
}
public function getDomain($domain) {
$domain = strtolower($domain);
$domain = str_replace(['www.','WWW.','https://','http://','https','http'], [''], $domain);
if($this->endsWith($domain, '/')){
$domain = substr_replace($domain ,"",-1);
}
return $domain;
}
public function endsWith($haystack, $needle) {
return $needle === "" || (($temp = strlen($haystack) - strlen($needle)) >= 0 && strpos($haystack, $needle, $temp) !== false);
}
}
138 changes: 138 additions & 0 deletions Helper/Data.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
<?php
/**
* Landofcoder
*
* 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://landofcoder.com/license
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this extension to newer
* version in the future.
*
* @category Landofcoder
* @package Lof_All
* @copyright Copyright (c) 2017 Landofcoder (https://www.landofcoder.com/)
* @license https://www.landofcoder.com/LICENSE-1.0.html
*/

namespace Lof\All\Helper;

use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Module\Dir;

class Data extends \Magento\Framework\App\Helper\AbstractHelper
{
/**
* @var \Magento\Store\Model\StoreManagerInterface
*/
protected $_storeManager;

/**
* @var array
*/
protected $_config = [];

/**
* Template filter factory
*
* @var \Magento\Catalog\Model\Template\Filter\Factory
*/
protected $_templateFilterFactory;

/**
* @var \Magento\Cms\Model\Template\FilterProvider
*/
protected $_filterProvider;

/**
* @var \Magento\Framework\Registry
*/
protected $_filesystem;

/**
* @var \Magento\Framework\Registry
*/
protected $_coreRegistry;

public function __construct(
\Magento\Framework\App\Helper\Context $context,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Cms\Model\Template\FilterProvider $filterProvider,
\Magento\Framework\Filesystem $filesystem,
\Magento\Framework\Registry $registry,
\Magento\Framework\Module\Dir\Reader $moduleReader,
\Lof\All\Model\License $licnese
) {
parent::__construct($context);
$this->_storeManager = $storeManager;
$this->_filterProvider = $filterProvider;
$this->_filesystem = $filesystem;
$this->_coreRegistry = $registry;
$this->_license = $licnese;
$this->_remoteAddress = $context->getRemoteAddress();
$this->_moduleReader = $moduleReader;
}

/**
* Return brand config value by key and store
*
* @param string $key
* @param \Magento\Store\Model\Store|int|string $store
* @return string|null
*/
public function getConfig($key, $group = "lofall/general", $store = null)
{
$store = $this->_storeManager->getStore($store);
$websiteId = $store->getWebsiteId();
if ($this->_storeManager->isSingleStoreMode()) {
$result = $this->scopeConfig->getValue(
$group . '/' .$key,
\Magento\Store\Model\ScopeInterface::SCOPE_WEBSITES
);
} else {
$result = $this->scopeConfig->getValue(
$group . '/' .$key,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
$store);
}
if(!$result){
$result = $this->scopeConfig->getValue(
$group . '/' .$key,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
null);
}
if(!$result){
$result = $this->scopeConfig->getValue(
$group . '/' .$key);
}

return $result;
}

public function filter($str)
{
$html = $this->_filterProvider->getPageFilter()->filter($str);
return $html;
}

public function getLicense($module_name) {
$ip = $this->_remoteAddress->getRemoteAddress();
$file = $this->_moduleReader->getModuleDir(Dir::MODULE_ETC_DIR, $module_name) . '/license.xml';
if(file_exists($file)) {
$xmlObj = new \Magento\Framework\Simplexml\Config($file);
$xmlData = $xmlObj->getNode();
if ($xmlData) {
$code = $xmlData->code;
$license = $this->_license->load($code);
return $license;
}
return false;
} else {
return true;
}
}
}
Loading

0 comments on commit 76659f3

Please sign in to comment.