Skip to content

Commit 1c68fd9

Browse files
authored
Merge pull request #7 from mageplaza/2.4-develop
2.4 develop
2 parents 40d2d5f + 3ea071b commit 1c68fd9

File tree

9 files changed

+38
-40
lines changed

9 files changed

+38
-40
lines changed

Block/Widget.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
namespace Mageplaza\TwitterWidget\Block;
2323

2424
use Magento\Framework\View\Element\Template;
25+
use Magento\Framework\Module\Manager;
2526
use Magento\Widget\Block\BlockInterface;
2627
use Mageplaza\TwitterWidget\Helper\Data;
2728
use Mageplaza\TwitterWidget\Model\Config\Source\Design;
@@ -38,6 +39,11 @@ class Widget extends Template implements BlockInterface
3839
*/
3940
protected $_template = "twitter.phtml";
4041

42+
/**
43+
* @var Manager
44+
*/
45+
protected $moduleManager;
46+
4147
/**
4248
* @var Data
4349
*/
@@ -52,9 +58,11 @@ class Widget extends Template implements BlockInterface
5258
*/
5359
public function __construct(
5460
Template\Context $context,
61+
Manager $moduleManager,
5562
Data $helperData,
5663
array $data = []
5764
) {
65+
$this->moduleManager = $moduleManager;
5866
$this->helperData = $helperData;
5967

6068
parent::__construct($context, $data);
@@ -65,7 +73,7 @@ public function __construct(
6573
*/
6674
public function isEnable()
6775
{
68-
return $this->helperData->isEnabled();
76+
return $this->helperData->isEnabled() && $this->moduleManager->isOutputEnabled('Mageplaza_TwitterWidget');
6977
}
7078

7179
/**

Controller/Twitter/Index.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
use Magento\Framework\HTTP\Adapter\CurlFactory;
3333
use Mageplaza\TwitterWidget\Helper\Data;
3434
use Psr\Log\LoggerInterface;
35-
use Zend_Http_Client;
35+
use Laminas\Http\Request;
3636

3737
/**
3838
* Class Twitter
@@ -125,11 +125,11 @@ public function getEmbedResponse($params)
125125
{
126126
$result = [];
127127
$params['omit_script'] = '1';
128-
$url = 'https://publish.twitter.com/oembed?' . http_build_query($params, null, '&');
128+
$url = 'https://publish.twitter.com/oembed?' . http_build_query($params, "", '&');
129129

130130
/** @var Curl $curl */
131131
$curl = $this->curlFactory->create();
132-
$curl->write(Zend_Http_Client::GET, $url, '1.1', [], '');
132+
$curl->write(Request::METHOD_GET, $url, '1.1', [], '');
133133

134134
try {
135135
$resultCurl = $curl->read();

Helper/Data.php

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

2424
use Mageplaza\Core\Helper\AbstractData;
25-
use Zend_Http_Response;
2625

2726
/**
2827
* Class Data
@@ -56,16 +55,6 @@ public function getTheme($store = null)
5655
return $this->getDisplayConfig('theme', $store);
5756
}
5857

59-
/**
60-
* @param null $store
61-
*
62-
* @return mixed
63-
*/
64-
public function getBorderColor($store = null)
65-
{
66-
return $this->getDisplayConfig('border_color', $store);
67-
}
68-
6958
/**
7059
* @param null $store
7160
*
@@ -123,6 +112,23 @@ public function getJsonDecode($data)
123112
*/
124113
public function getHttpResponse($data)
125114
{
126-
return Zend_Http_Response::extractBody($data);
115+
return $this->extractBody($data);
116+
}
117+
118+
/**
119+
* Extract the body from a response string
120+
*
121+
* @param string $response_str
122+
*
123+
* @return string
124+
*/
125+
public static function extractBody($response_str)
126+
{
127+
$parts = preg_split('|(?:\r\n){2}|m', $response_str, 2);
128+
if (isset($parts[1])) {
129+
return $parts[1];
130+
}
131+
132+
return '';
127133
}
128134
}

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
"name": "mageplaza/module-twitter-widget",
33
"description": "Magento 2 Twitter Widget Extension",
44
"require": {
5-
"mageplaza/module-core": "^1.4.5"
5+
"mageplaza/module-core": "^1.5.4"
66
},
77
"type": "magento2-module",
8-
"version": "4.0.1",
8+
"version": "4.0.2",
99
"license": "proprietary",
1010
"authors": [
1111
{

etc/adminhtml/system.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,6 @@
5454
<label>Theme</label>
5555
<source_model>Mageplaza\TwitterWidget\Model\Config\Source\Theme</source_model>
5656
</field>
57-
<field id="border_color" translate="label comment" type="text" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
58-
<label>Border color</label>
59-
<comment>Color of border surrounding a Twitter widget.</comment>
60-
<validate>jscolor {hash:true,refine:false} required-entry</validate>
61-
</field>
6257
<field id="width" translate="label comment" type="text" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
6358
<label>Widget width</label>
6459
<validate>validate-zero-or-greater validate-number validate-digits validate-digits-range digits-range-180-1200</validate>

etc/config.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
</general>
3333
<display>
3434
<theme>light</theme>
35-
<border_color>#73818f</border_color>
3635
<height>600</height>
3736
</display>
3837
</mptwitterwidget>

etc/widget.xml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,6 @@
4444
<parameter name="design" value="1"/>
4545
</depends>
4646
</parameter>
47-
<parameter name="border_color" xsi:type="text" visible="true" required="true">
48-
<label translate="true">Border color</label>
49-
<description translate="true"><![CDATA[Color of border surrounding a Twitter widget. Use hex code. Refer <a href="https://www.w3schools.com/colors/colors_picker.asp" target="_blank">here</a>]]></description>
50-
<depends>
51-
<parameter name="design" value="1"/>
52-
</depends>
53-
<value>#73818f</value>
54-
</parameter>
5547
<parameter name="width" xsi:type="text" visible="true">
5648
<label translate="true">Widget width</label>
5749
<description translate="true">Set the maximum width of the widget. Minimum: 180, maximum: 1200. If empty, auto width will be use</description>

i18n/en_US.csv

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ Username,Username
2323
"The Twitter username of the account you would like the viewer to follow","The Twitter username of the account you would like the viewer to follow"
2424
Display,Display
2525
Theme,Theme
26-
"Link color","Link color"
27-
"Color of link text inside a Twitter widget.","Color of link text inside a Twitter widget."
28-
"Border color","Border color"
29-
"Color of border surrounding a Twitter widget.","Color of border surrounding a Twitter widget."
3026
"Widget width","Widget width"
3127
"Set the maximum width of the widget. Minimum: 180, maximum: 1200. If empty, auto width will be use","Set the maximum width of the widget. Minimum: 180, maximum: 1200. If empty, auto width will be use"
3228
"Widget height","Widget height"
@@ -37,8 +33,6 @@ Example,Example
3733
Title,Title
3834
Description,Description
3935
Type,Type
40-
"Color of link text inside a Twitter widget. Use hex code. Refer <a href=""https://www.w3schools.com/colors/colors_picker.asp"" target=""_blank"">here</a>","Color of link text inside a Twitter widget. Use hex code. Refer <a href=""https://www.w3schools.com/colors/colors_picker.asp"" target=""_blank"">here</a>"
41-
"Color of border surrounding a Twitter widget. Use hex code. Refer <a href=""https://www.w3schools.com/colors/colors_picker.asp"" target=""_blank"">here</a>","Color of border surrounding a Twitter widget. Use hex code. Refer <a href=""https://www.w3schools.com/colors/colors_picker.asp"" target=""_blank"">here</a>"
4236
"Tweet URL","Tweet URL"
4337
"Hide thread","Hide thread"
4438
"Excluding previous Tweets in the reply thread","Excluding previous Tweets in the reply thread"

view/frontend/web/js/twitter.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ define(
4040
default_param = {
4141
url: this.options.url,
4242
theme: this.options.params.theme,
43-
border_color: this.options.params.border_color,
4443
maxWidth: this.options.params.width,
4544
maxHeight: this.options.params.height
4645
},
@@ -67,7 +66,12 @@ define(
6766
'width' : default_param.maxWidth + 'px',
6867
'height' : default_param.maxHeight + 'px'
6968
});
70-
$('.mptwitterwidget-header').css('width', default_param.maxWidth);
69+
if (default_param.maxWidth) {
70+
$('.mptwitterwidget-header').css('width', default_param.maxWidth);
71+
} else {
72+
$('.mptwitterwidget-header').css('min-width', '350px');
73+
}
74+
7175
twttr.widgets.load(element);
7276
// create follow button if enable
7377
if (follow_btn === '1') {

0 commit comments

Comments
 (0)