1+ <?php
2+ /**
3+ * Landofcoder
4+ *
5+ * NOTICE OF LICENSE
6+ *
7+ * This source file is subject to the venustheme.com license that is
8+ * available through the world-wide-web at this URL:
9+ * http://landofcoder.com/license
10+ *
11+ * DISCLAIMER
12+ *
13+ * Do not edit or add to this file if you wish to upgrade this extension to newer
14+ * version in the future.
15+ *
16+ * @category Landofcoder
17+ * @package Lof_All
18+ * @copyright Copyright (c) 2017 Landofcoder (https://www.landofcoder.com/)
19+ * @license https://www.landofcoder.com/LICENSE-1.0.html
20+ */
21+
22+ namespace Lof \All \Block \Adminhtml \System ;
23+
24+ use Magento \Framework \App \Filesystem \DirectoryList ;
25+ use Lof \All \Block \Adminhtml \System \ListLicense ;
26+
27+ class Market extends \Magento \Config \Block \System \Config \Form \Field
28+ {
29+
30+ /**
31+ * @var \Magento\Framework\App\ResourceConnection
32+ */
33+ protected $ _resource ;
34+
35+ protected $ _key_path ;
36+
37+ /**
38+ * [__construct description]
39+ * @param \Magento\Backend\Block\Template\Context $context
40+ * @param \Magento\Framework\App\ResourceConnection $resource
41+ * @param \Lof\All\Helper\Data $helper
42+ * @param \Magento\Framework\HTTP\PhpEnvironment\RemoteAddress $remoteAddress
43+ */
44+ public function __construct (
45+ \Magento \Backend \Block \Template \Context $ context ,
46+ \Magento \Framework \App \ResourceConnection $ resource ,
47+ \Lof \All \Helper \Data $ helper ,
48+ \Lof \All \Model \License $ license ,
49+ \Magento \Framework \HTTP \PhpEnvironment \RemoteAddress $ remoteAddress
50+ )
51+ {
52+ parent ::__construct ($ context );
53+ $ this ->_resource = $ resource ;
54+ $ this ->_helper = $ helper ;
55+ $ this ->_remoteAddress = $ remoteAddress ;
56+ $ this ->_license = $ license ;
57+ }
58+
59+ /**
60+ * Retrieve HTML markup for given form element
61+ *
62+ * @param \Magento\Framework\Data\Form\Element\AbstractElement $element
63+ * @return string
64+ */
65+ public function render (\Magento \Framework \Data \Form \Element \AbstractElement $ element )
66+ {
67+ /*
68+ if (!extension_loaded('soap')) {
69+ throw new \Magento\Framework\Webapi\Exception(
70+ __('SOAP extension is not loaded.'),
71+ 0,
72+ \Magento\Framework\Webapi\Exception::HTTP_INTERNAL_ERROR
73+ );
74+ }
75+ $products = array();
76+ try{
77+ $opts = array(
78+ 'ssl' => array(
79+ 'verify_peer' => false,
80+ 'verify_peer_name' => false
81+ )
82+ );
83+ $context = stream_context_create($opts);
84+ $params = array('soap_version'=>SOAP_1_2,
85+ 'verifypeer' => false,
86+ 'verifyhost' => false,
87+ 'exceptions' => 1,
88+ 'stream_context'=>$context);
89+
90+ $proxy = new \SoapClient(ListLicense::API_URL, $params);
91+
92+ $sessionId = $proxy->login(ListLicense::API_USERNAME, ListLicense::API_PASSWORD);
93+
94+ $products = $proxy->call($sessionId, 'veslicense.productlist1');
95+ } catch(SoapFault $e){
96+
97+ }*/
98+ $ list_products = $ this ->getProductList ();
99+ $ products = isset ($ list_products ['products ' ])?$ list_products ['products ' ]:[];
100+ $ total = 12 ;
101+ $ column = 2 ;
102+ $ x = 0 ;
103+ $ html = '' ;
104+ $ html .= '<div id="lof-elist"> ' ;
105+ $ html .= '<h1><a href="https://landofcoder.com">Landofcoder.com - Opensource Marketplace for magento, opencart</a></h1> ' ;
106+ foreach ($ products as $ _product ) {
107+ if ( $ column == 1 || $ x %$ column == 0 ){
108+ $ html .= '<div class="erow"> ' ;
109+ }
110+ $ class = '' ;
111+ if ( $ column == 1 || ($ x +1 )%$ column == 0 || $ x == ($ total -1 ) ) {
112+ $ class = ' last ' ;
113+ }
114+
115+ if ($ _product ['price ' ]==0 || $ _product ['price ' ]=="" ||$ _product ['price ' ]=="0.00 " || $ _product ['price ' ]=="$0.00 " || !$ _product ['price ' ]) {
116+ $ price = 'FREE ' ;
117+ } else {
118+ $ price = $ _product ['price_currency ' ];
119+ }
120+
121+ $ html .= '<div class="extend-card ' . $ class . '"> ' ;
122+ $ html .= '<div class="extend-card-top"> ' ;
123+ $ html .= '<div class="extend-card-image"><a href=" ' . $ _product ['purl ' ] . '" title=" ' . $ _product ['name ' ] . '"><img src=" ' . $ _product ['pimg ' ] . '" class="plugin-icon" alt=""></a></div> ' ;
124+ $ 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> ' ;
125+ $ html .= '</div> ' ;
126+ $ html .= '</div> ' ;
127+ if ( $ column == 1 || ($ x +1 )%$ column == 0 || $ x == ($ total -1 ) ) {
128+ $ html .= '</div> ' ;
129+ }
130+ $ x ++;
131+ }
132+ $ html .= '</div> ' ;
133+
134+ return $ this ->_decorateRowHtml ($ element , $ html );
135+ }
136+ public function getProductList () {
137+ //Authentication rest API magento2, get access token
138+ $ url = ListLicense::getListUrl ();
139+ $ key_path = $ this ->getKeyPath ();
140+ $ data = array ();
141+ $ crl = curl_init ();
142+ curl_setopt ($ crl , CURLOPT_SSL_VERIFYPEER , TRUE );
143+ curl_setopt ($ crl , CURLOPT_CAPATH , $ key_path );
144+ curl_setopt ($ crl , CURLOPT_SSL_VERIFYHOST , 2 );
145+ curl_setopt ($ crl , CURLOPT_URL , $ url );
146+ curl_setopt ($ crl , CURLOPT_HEADER , 0 );
147+ curl_setopt ($ crl , CURLOPT_RETURNTRANSFER , 1 );
148+ curl_setopt ($ crl , CURLOPT_POST , 1 );
149+ curl_setopt ($ crl , CURLOPT_POSTFIELDS , $ data );
150+ $ response = curl_exec ($ crl );
151+ if ($ response ) {
152+ }
153+ else {
154+ echo 'An error has occurred: ' . curl_error ($ crl );
155+ return [];
156+ }
157+ curl_close ($ crl );
158+
159+ return json_decode ($ response , true );
160+ }
161+
162+ public function getKeyPath (){
163+ if (!$ this ->_key_path ){
164+ $ objectManager = \Magento \Framework \App \ObjectManager::getInstance ();
165+ $ directory = $ objectManager ->get ('\Magento\Framework\Filesystem\DirectoryList ' );
166+ $ base_url = $ directory ->getRoot ();
167+ $ this ->_key_path = $ base_url ."/veslicense/cacert.pem " ;
168+ }
169+ return $ this ->_key_path ;
170+ }
171+ public function getDomain ($ domain ) {
172+ $ domain = strtolower ($ domain );
173+ $ domain = str_replace (['www. ' ,'WWW. ' ,'https:// ' ,'http:// ' ,'https ' ,'http ' ], ['' ], $ domain );
174+ if ($ this ->endsWith ($ domain , '/ ' )){
175+ $ domain = substr_replace ($ domain ,"" ,-1 );
176+ }
177+ return $ domain ;
178+ }
179+ public function endsWith ($ haystack , $ needle ) {
180+ return $ needle === "" || (($ temp = strlen ($ haystack ) - strlen ($ needle )) >= 0 && strpos ($ haystack , $ needle , $ temp ) !== false );
181+ }
182+ }
0 commit comments