Skip to content

Commit bbceaae

Browse files
Merge pull request #3 from mageplaza/develop
Develop
2 parents 06acc41 + 116c855 commit bbceaae

File tree

21 files changed

+714
-942
lines changed

21 files changed

+714
-942
lines changed

Block/Adminhtml/System/Snippet.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
class Snippet extends Field
3333
{
3434
/**
35-
* @param AbstractElement $element
35+
* @param AbstractElement $element
3636
*
3737
* @return string
3838
*/
@@ -47,7 +47,7 @@ protected function _getElementHtml(AbstractElement $element)
4747

4848
$html .= __('Template .phtml file');
4949
$html .= '</strong><br /><pre style="background-color: #f5f5dc;"><code>' . $this->_escaper->escapeHtml(
50-
'<?php echo $block->getLayout()->createBlock(\Mageplaza\TwitterWidget\Block\Widget::class)->setData([
50+
'<?php echo $block->getLayout()->createBlock(\Mageplaza\TwitterWidget\Block\Widget::class)->setData([
5151
"title" => "Twitter timeline",
5252
"description" => "",
5353
"design" => "0",
@@ -56,11 +56,11 @@ protected function _getElementHtml(AbstractElement $element)
5656
"limit" => "10"
5757
])
5858
->toHtml();?>'
59-
) . '</code></pre><strong>';
59+
) . '</code></pre><strong>';
6060

6161
$html .= __('Layout file');
6262
$html .= '</strong><br /><pre style="background-color: #f5f5dc;"><code>' . $this->_escaper->escapeHtml(
63-
'<block class="Mageplaza\TwitterWidget\Block\Widget" name="mp_twitter_widget" >
63+
'<block class="Mageplaza\TwitterWidget\Block\Widget" name="mp_twitter_widget" >
6464
<arguments>
6565
<argument name="title" xsi:type="string">Twitter timeline</argument>
6666
<argument name="description" xsi:type="string"></argument>
@@ -70,7 +70,7 @@ protected function _getElementHtml(AbstractElement $element)
7070
<argument name="limit" xsi:type="string">10</argument>
7171
</arguments>
7272
</block>'
73-
) . '</code></pre>';
73+
) . '</code></pre>';
7474

7575
$html .= '</div>';
7676

Block/Widget.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,12 @@ public function getAllOptions()
8989

9090
return Data::jsonEncode($this->getData());
9191
}
92+
93+
/**
94+
* @return string
95+
*/
96+
public function getRequestUrl()
97+
{
98+
return $this->_urlBuilder->getUrl('mptwitterwidget/twitter/');
99+
}
92100
}

CHANGELOG

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
CHANGELOG: https://www.mageplaza.com/releases/twitter-widget/
1+
CHANGELOG: https://www.mageplaza.com/releases/twitter-widget/

Controller/Twitter/Index.php

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,18 @@
2121

2222
namespace Mageplaza\TwitterWidget\Controller\Twitter;
2323

24+
use Exception;
2425
use Magento\Framework\App\Action\Action;
2526
use Magento\Framework\App\Action\Context;
27+
use Magento\Framework\App\ResponseInterface;
28+
use Magento\Framework\Controller\Result\Json;
29+
use Magento\Framework\Controller\Result\JsonFactory;
30+
use Magento\Framework\Controller\ResultInterface;
31+
use Magento\Framework\HTTP\Adapter\Curl;
2632
use Magento\Framework\HTTP\Adapter\CurlFactory;
2733
use Mageplaza\TwitterWidget\Helper\Data;
2834
use Psr\Log\LoggerInterface;
35+
use Zend_Http_Client;
2936

3037
/**
3138
* Class Twitter
@@ -49,35 +56,43 @@ class Index extends Action
4956
*/
5057
protected $_helperData;
5158

59+
/**
60+
* @var JsonFactory
61+
*/
62+
protected $resultJsonFactory;
63+
5264
/**
5365
* Index constructor.
5466
*
5567
* @param Context $context
5668
* @param CurlFactory $curlFactory
5769
* @param Data $helperData
70+
* @param JsonFactory $jsonFactory
5871
* @param LoggerInterface $logger
5972
*/
6073
public function __construct(
6174
Context $context,
6275
CurlFactory $curlFactory,
6376
Data $helperData,
77+
JsonFactory $jsonFactory,
6478
LoggerInterface $logger
6579
) {
66-
$this->curlFactory = $curlFactory;
67-
$this->_helperData = $helperData;
68-
$this->logger = $logger;
80+
$this->curlFactory = $curlFactory;
81+
$this->_helperData = $helperData;
82+
$this->resultJsonFactory = $jsonFactory;
83+
$this->logger = $logger;
6984

7085
parent::__construct($context);
7186
}
7287

7388
/**
74-
* @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface
89+
* @return ResponseInterface|ResultInterface
7590
*/
7691
public function execute()
7792
{
7893
$result = ['status' => false];
7994
try {
80-
$params = $this->getRequest()->getParams();
95+
$params = $this->getRequest()->getParams();
8196
$response = $this->getEmbedResponse($params);
8297
if (array_key_exists('html', $response)) {
8398
$result = [
@@ -90,12 +105,15 @@ public function execute()
90105
'content' => $response['message']
91106
];
92107
}
93-
} catch (\Exception $e) {
108+
} catch (Exception $e) {
94109
$result['content'] = $e->getMessage();
95110
$this->logger->critical($e);
96111
}
97112

98-
return $this->getResponse()->representJson($this->_helperData->getJsonEncode($result));
113+
/** @var Json $resultJson */
114+
$resultJson = $this->resultJsonFactory->create();
115+
116+
return $resultJson->setData($result);
99117
}
100118

101119
/**
@@ -105,24 +123,24 @@ public function execute()
105123
*/
106124
public function getEmbedResponse($params)
107125
{
108-
$result = [];
126+
$result = [];
109127
$params['omit_script'] = '1';
110-
$url = 'https://publish.twitter.com/oembed?' . http_build_query($params, null, '&');
128+
$url = 'https://publish.twitter.com/oembed?' . http_build_query($params, null, '&');
111129

112-
/** @var \Magento\Framework\HTTP\Adapter\Curl $curl */
130+
/** @var Curl $curl */
113131
$curl = $this->curlFactory->create();
114-
$curl->write(\Zend_Http_Client::GET, $url, '1.1', [], '');
132+
$curl->write(Zend_Http_Client::GET, $url, '1.1', [], '');
115133

116134
try {
117135
$resultCurl = $curl->read();
118136
if (!empty($resultCurl)) {
119137
$responseBody = $this->_helperData->getHttpResponse($resultCurl);
120-
$result += $this->_helperData->getJsonDecode($responseBody);
138+
$result += $this->_helperData->getJsonDecode($responseBody);
121139
if (!count($result)) {
122140
$result['message'] = __('Sorry, that twitter page doesn\'t exist!');
123141
}
124142
}
125-
} catch (\Exception $e) {
143+
} catch (Exception $e) {
126144
$result['message'] = $e->getMessage();
127145
}
128146

Helper/Data.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
namespace Mageplaza\TwitterWidget\Helper;
2323

2424
use Mageplaza\Core\Helper\AbstractData;
25+
use Zend_Http_Response;
2526

2627
/**
2728
* Class Data
@@ -115,16 +116,6 @@ public function getUsername($store = null)
115116
return $this->getConfigGeneral('username', $store);
116117
}
117118

118-
/**
119-
* @param $data
120-
*
121-
* @return string
122-
*/
123-
public function getJsonEncode($data)
124-
{
125-
return Data::jsonEncode($data);
126-
}
127-
128119
/**
129120
* @param $data
130121
*
@@ -142,6 +133,6 @@ public function getJsonDecode($data)
142133
*/
143134
public function getHttpResponse($data)
144135
{
145-
return \Zend_Http_Response::extractBody($data);
136+
return Zend_Http_Response::extractBody($data);
146137
}
147138
}

LICENSE

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
1-
Copyright © 2016-present Mageplaza Co. Ltd.
2-
3-
This License is entered by Mageplaza to govern the usage or redistribution of Mageplaza software. This is a legal agreement between you (either an individual or a single entity) and Mageplaza for Mageplaza software product(s) which may include extensions, templates and services.
4-
5-
By purchasing, installing, or otherwise using Mageplaza products, you acknowledge that you have read this License and agree to be bound by the terms of this Agreement. If you do not agree to the terms of this License, do not install or use Mageplaza products.
6-
7-
The Agreement becomes effective at the moment when you acquire software from our site or receive it through email or on data medium or by any other means. Mageplaza reserves the right to make reasonable changes to the terms of this license agreement and impose its clauses at any given time.
8-
9-
1. GRANT OF LICENSE: By purchasing a product of Mageplaza:
10-
11-
1. Customer will receive source code open 100%.
12-
13-
2. Customer will obtain a License Certificate which will remain valid until the Customer stops using the Product or until Mageplaza terminates this License because of Customer’s failure to comply with any of its Terms and Conditions. Each License Certificate includes a license serial which is valid for one live Magento installation only and unlimited test Magento installations.
14-
15-
3. You are allowed to customize our products to fit with your using purpose.
16-
17-
4. DESCRIPTION OF OTHER RIGHTS AND LIMITATIONS
18-
19-
5. Installation and Use
20-
21-
6. For each new Software installation, you are obliged to purchase a separate License. You are not permitted to use any part of the code in whole or part in any other software or product or website. You are legally bound to preserve the copyright information intact including the text/link at bottom.
22-
23-
2. Distribution: You are not allowed to distribute Mageplaza software to third parties. Any distribution without our permission, including non commercial distribution is considered as violation of this Agreement and entails liability, according to the current law. You may not place the Software onto a server that allows access to the Software via a public network or the Internet for distribution purposes.
24-
25-
3. Rental: You may not give, sell, sub-license, rent, lease or lend any portion of the Software to anyone.
26-
27-
4. Compliance with Applicable Laws: You must comply with all applicable laws regarding use of software products. Mageplaza software and a portion of it are protected by copyright laws and international copyright treaties, as well as other intellectual property laws and treaties. Accordingly, customer is required to treat the software like any other copyrighted material. Any activity violating copyright law will be prosecuted according to the current law. We retain the right to revoke the license of any user holding an invalid license.
28-
29-
5. TERMINATION: Without prejudice to any other rights, Mageplaza may terminate this License at any time if you fail to comply with the terms and conditions of this License. In such event, it constitutes a breach of the agreement, and your license to use the program is revoked and you must destroy all copies of Mageplaza products in your possession. After being notified of termination of your license, if you continue to use Mageplaza software, you hereby agree to accept an injunction to prevent you from its further use and to pay all costs (including but not limited to reasonable attorney fees) to enforce our revocation of your license and any damages suffered by us because of your misuse of the Software. We are not bound to return you the amount spent for purchase of the Software for the termination of this License.
30-
31-
6. LIMITATION OF LIABILITY: In no event shall Mageplaza be liable for any damages (including, without limitation, lost profits, business interruption, or lost information) rising out of ‘Authorized Users’ use of or inability to use the Mageplaza products, even if Mageplaza has been advised of the possibility of such damages. In no event will Mageplaza be liable for prosecution arising from use of the Software against law or for any illegal use.
32-
1+
Copyright © 2016-present Mageplaza Co. Ltd.
2+
3+
This License is entered by Mageplaza to govern the usage or redistribution of Mageplaza software. This is a legal agreement between you (either an individual or a single entity) and Mageplaza for Mageplaza software product(s) which may include extensions, templates and services.
4+
5+
By purchasing, installing, or otherwise using Mageplaza products, you acknowledge that you have read this License and agree to be bound by the terms of this Agreement. If you do not agree to the terms of this License, do not install or use Mageplaza products.
6+
7+
The Agreement becomes effective at the moment when you acquire software from our site or receive it through email or on data medium or by any other means. Mageplaza reserves the right to make reasonable changes to the terms of this license agreement and impose its clauses at any given time.
8+
9+
1. GRANT OF LICENSE: By purchasing a product of Mageplaza:
10+
11+
1. Customer will receive source code open 100%.
12+
13+
2. Customer will obtain a License Certificate which will remain valid until the Customer stops using the Product or until Mageplaza terminates this License because of Customer’s failure to comply with any of its Terms and Conditions. Each License Certificate includes a license serial which is valid for one live Magento installation only and unlimited test Magento installations.
14+
15+
3. You are allowed to customize our products to fit with your using purpose.
16+
17+
4. DESCRIPTION OF OTHER RIGHTS AND LIMITATIONS
18+
19+
5. Installation and Use
20+
21+
6. For each new Software installation, you are obliged to purchase a separate License. You are not permitted to use any part of the code in whole or part in any other software or product or website. You are legally bound to preserve the copyright information intact including the text/link at bottom.
22+
23+
2. Distribution: You are not allowed to distribute Mageplaza software to third parties. Any distribution without our permission, including non commercial distribution is considered as violation of this Agreement and entails liability, according to the current law. You may not place the Software onto a server that allows access to the Software via a public network or the Internet for distribution purposes.
24+
25+
3. Rental: You may not give, sell, sub-license, rent, lease or lend any portion of the Software to anyone.
26+
27+
4. Compliance with Applicable Laws: You must comply with all applicable laws regarding use of software products. Mageplaza software and a portion of it are protected by copyright laws and international copyright treaties, as well as other intellectual property laws and treaties. Accordingly, customer is required to treat the software like any other copyrighted material. Any activity violating copyright law will be prosecuted according to the current law. We retain the right to revoke the license of any user holding an invalid license.
28+
29+
5. TERMINATION: Without prejudice to any other rights, Mageplaza may terminate this License at any time if you fail to comply with the terms and conditions of this License. In such event, it constitutes a breach of the agreement, and your license to use the program is revoked and you must destroy all copies of Mageplaza products in your possession. After being notified of termination of your license, if you continue to use Mageplaza software, you hereby agree to accept an injunction to prevent you from its further use and to pay all costs (including but not limited to reasonable attorney fees) to enforce our revocation of your license and any damages suffered by us because of your misuse of the Software. We are not bound to return you the amount spent for purchase of the Software for the termination of this License.
30+
31+
6. LIMITATION OF LIABILITY: In no event shall Mageplaza be liable for any damages (including, without limitation, lost profits, business interruption, or lost information) rising out of ‘Authorized Users’ use of or inability to use the Mageplaza products, even if Mageplaza has been advised of the possibility of such damages. In no event will Mageplaza be liable for prosecution arising from use of the Software against law or for any illegal use.
32+
3333
The latest License: https://www.mageplaza.com/LICENSE.txt

0 commit comments

Comments
 (0)